harbor run -t openthoughts/tasktrove-exp-rpt-taco-v2-taco-4198harbor download openthoughts/tasktrove-exp-rpt-taco-v2-taco-4198Problem Statement:
Jenish, the most dangerous cyborg, is trapped on a narrow bridge spanning a valley. The bridge has a length of ( N ) meters, where each position ( i ) represents the section of the bridge with its left border at distance ( i-1 ) meters from the left end and its right border at distance ( i ) meters. There are ( N ) batteries positioned at locations ( 1, 2, \ldots, N ), and each battery ( i ) has an energy value of ( a[i] ).
Two tanks of strength ( X ) are located at positions ( 0 ) and ( N+1 ). Initially, Jenish has ( 0 ) energy.
Starting from time ( t = 1 ), the following actions occur:
If at any point Jenish's total energy is greater than or equal to ( X ), he destroys the tanks and escapes. If by the end of the ( \left\lfloor \frac{(N+1)}{2} \right\rfloor ) second he has not amassed enough energy to destroy the tanks, he is destroyed. Your task is to determine if Jenish can escape.
For each test case, print YES if Jenish can escape and NO if he gets destroyed.
3
4 8
5 1 4 2
3 4
3 1 2
2 7
5 5
YES
YES
NO
In the first test case, Jenish can select the battery at index 1 first, then the tanks move closer, destroying the battery at index 4. In the second second, he can select battery at index 3, remaining with a total energy of 9 which is sufficient to destroy the tanks.
In the second test case, he can use batteries at indices 1 and 2 to achieve a total of 4 energy which meets the requirement.
In the third test case, regardless of the batteries selected, he can achieve a maximum of 5 energy, which is insufficient.
Please place your solution in the /app/ directory.
Important: place your implementation at /app/solution.py so the verifier can run it.