0% found this document useful (0 votes)
70 views

Task 3: Feast: Input

Gug is preparing a feast for his friends consisting of N plates of food arranged in a single row, with the ith plate giving satisfaction points Ai that can be positive or negative. K people will each be assigned a consecutive segment of plates to eat to maximize the total satisfaction points, without overlapping segments. The program must read N and K, the satisfaction points A1 to AN, and output the maximum total satisfaction points.

Uploaded by

dragon slayer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Task 3: Feast: Input

Gug is preparing a feast for his friends consisting of N plates of food arranged in a single row, with the ith plate giving satisfaction points Ai that can be positive or negative. K people will each be assigned a consecutive segment of plates to eat to maximize the total satisfaction points, without overlapping segments. The program must read N and K, the satisfaction points A1 to AN, and output the maximum total satisfaction points.

Uploaded by

dragon slayer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Task 3: Feast

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

NOI 2019 National Olympiad in Informatics—Singapore 7


Your program will be tested on input instances that satisfy the following restrictions:

Subtask Marks Additional Constraints


1 4 Ai ≥ 0
2 8 There will be at most one position where Ai < 0.
3 18 K=1
4 10 1 ≤ K ≤ N ≤ 80
5 11 1 ≤ K ≤ N ≤ 300
6 20 1 ≤ K ≤ N ≤ 2000
7 29 -

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 1 Explanation


It is optimal to assign the only person to the segment [3, -1, 5].

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

Sample Testcase 2 Explanation


Picking the consecutive segments [1, 2, 3] and [5, 6] is the most optimal solution.

NOI 2019 National Olympiad in Informatics—Singapore 8


Sample Testcase 3
This testcase is valid for subtasks 4, 5, 6 and 7.
Input Output
6 4 0
-1 -2 -1 0 -5 -1

Sample Testcase 3 Explanation


As all the satisfaction points are non-positive, it is optimal to choose empty segments for all
four people.

NOI 2019 National Olympiad in Informatics—Singapore 9

You might also like