Program time limit: 1 second
Program memory limit: 512 MB
Duck tito's duck empire has experienced the attacks of the incoming earthworms!!!
There are N incoming earthworms, each with a length of $A_i$, you can imagine them to be an array. Luckily, Duck tito has a valiant army of M duck solders, each of them has an eating power $E_i$, and eating time, $T_i$.
Being proud ducks, Duck tito can only send one duck soldier at a time to face the earthworm army. This duck soldier can apply its eating power, $E_i$ on any continuous range of the array of earth worms they like at once, however, dealing this eating power will cost the whole army $T_i$ worth of time, putting the empire into greater risk.
Each earthworm that got attacked with the eating power will have its length, $A_i$ decreased by $E_i$. If $A_i \leq 0$, the earthworm is dead and removed from the array.
Help Duck tito determine the shortest time required to eliminate the incoming earthworms!
You should read from standard input.
In Python, you could use the following code.
N, M = map(int, input().split())
A = list(map(int, input().split()))
E = []
T = []
for _ in range(M):
cost, power = map(int, input().split())
E.append(cost)
T.append(power)
In C or C++, you could use the following code.
scanf("%d %d", &N, &M);
for(int i = 0; i < N; i++) scanf("%d", &A[i]);
for(int i = 0; i < M; i++) scanf("%d %d", &E[i], &T[i]);
For all test cases:
Additionally:
one integer, the shortest time required.
You should write to standard output.
In Python, you could use the line print(answer).
In C or C++, you could use the line printf("%d\n", answer);.
5 2
3 3 3 5 5
5 3
3 2
3
In this case, if Duck Tito sending out the first duck once, it will eat all the earthworms if it chooses the range $[1,5]$. The total time will be $3$.
3 2
10 2 2
2 3
8 5
8
Duck Tito can send the first soldier with the eating power of $2$ to all the earth worms, and then send the second worm with the eating power of $8$ to eat the only remaining earthworm.
For all subtasks (worth $20\%$, $30\%$, and $50\%$ of points, as per the Constraints section), your program will be run on multiple secret test cases one after another, and if it produces the correct output for all test cases, it solves that subtask. Your program will receive the points for each subtask it solves. Recall that your final score on the task is the score of your highest scoring submission.
The contest ended at 8:16 p.m. AEST on Thursday 2nd July. All submissions will be unofficial .