Task 3: Feast: Input
Task 3: Feast: Input
Gug is preparing a feast for his friends. The feast consists of N plates of food arranged in a
single row, with the ith plate from the left giving Ai points of satisfaction if eaten. As some
plates of food might be rotten, it is possible that Ai is negative.
There are a total of K people involved in the feast, and each person will be assigned a consec-
utive segment of plates to consume. This segment can possibly be empty. The segments of two
people cannot overlap, as food cannot be eaten twice. Gug wishes to assign the plates to his
friends such that the sum of satisfaction points of all the plates of food consumed is maximised.
Input
Your program must read from standard input.
The input starts with a line with two integers N and K.
The next line will contain N integers A1 , . . . , AN .
Output
Your program must print to standard output.
The output should contain a single integer on a single line, the sum of satisfaction points in an
optimal assignment.
Subtasks
The maximum execution time on each instance is 1.0s. For all testcases, the input will satisfy
the following bounds:
• 1 ≤ K ≤ N ≤ 3 ∗ 105
• 0 ≤ |Ai | ≤ 109
Sample Testcase 1
This testcase is valid for subtasks 3, 4, 5, 6 and 7.
Input Output
6 1 7
1 -2 3 -1 5 -6
Sample Testcase 2
This testcase is valid for subtasks 2, 4, 5, 6 and 7.
Input Output
6 2 17
1 2 3 -10 5 6