P3097 [USACO13DEC] Optimal Milking G

Description

Farmer John has recently purchased a new barn containing N milking machines (1

Input Format

\* Line 1: The values of N and D. \* Lines 2..1+N: Line i+1 contains the initial value of M(i). \* Lines 2+N..1+N+D: Line 1+N+d contains two integers i and m, indicating that Farmer John updates the value of M(i) to m at the beginning of day d.

Output Format

\* Line 1: The maximum total amount of milk FJ can produce over D days.

Explanation/Hint

There are 5 machines, with initial milk outputs 1,2,3,4,5. On day 1, machine 5 is updated to output 2 unit of milk, and so on. On day one, the optimal amount of milk is 2+4 = 6 (also achievable as 1+3+2). On day two, the optimal amount is 7+4 = 11. On day three, the optimal amount is 10+3+2=15.