#BS0000484. Chia bánh (Cake Division)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chia bánh (Cake Division)
Cake Division
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A round cake has been divided into pieces by radial cut lines from its center to its circumference. Both pieces and cut lines are numbered clockwise from to . Piece has mass .
Cut line separates pieces and , with cut line separating piece from piece . Clockwise order therefore wraps from piece to piece .
Divide the entire cake among people. Each person must receive at least one piece, and all pieces assigned to that person must be consecutive around the circle. Each piece belongs to exactly one person.
Let be the total mass received by person . A division is optimal if its value of is the greatest among all valid divisions.
A cut line is used when the two pieces on either side belong to different people. Determine both the maximum possible value of and the number of cut lines that are unused in every optimal division.
Input
The first line contains two integers , the number of pieces and the number of recipients.
The second line contains integers , the masses of the pieces in clockwise order starting at piece 1.
Output
Print two integers on one line, separated by a space. Here is the largest possible minimum share mass, and counts the cut lines absent from every optimal division.
Subtasks
-
Subtask 1 (20 points): ; for every ; all input values are integers.
-
Subtask 2 (30 points): ; for every ; all input values are integers.
-
Subtask 3 (50 points): ; for every ; all input values are integers.
Examples
Input 1
5 2
3 6 8 6 4
Output 1
13 1
Explanation 1
The total mass is 27, so the smaller share cannot exceed 13. Cuts 1 and 3 give masses and . Cuts 2 and 4 give masses and . Thus , and cuts 1–4 occur in optimal divisions.
Using cut 5 would require a share beginning at piece 1 with mass 13 or 14. Its possible proper prefix masses are , none of which equals 13 or 14. Thus only cut 5 is absent from every optimal division, giving .
Input 2
6 3
4 7 11 3 9 2
Output 2
11 1
Explanation 2
Total mass is 36. A minimum of 12 requires three shares of exactly 12. Piece 3 weighs 11 by itself, and adding either neighboring piece exceeds 12; hence 12 is impossible.
Cut sets , , and give masses , , and , respectively. Thus , and cuts 2–6 can all be used.
If cut 1 is used, start at piece 2. The two shortest initial shares reaching 11 weigh 18 and 12, leaving only 6 for the final share. Cut 1 cannot appear in an optimal division; hence .
Input 3
10 3
2 9 8 1 7 9 1 3 5 8
Output 3
17 4
Explanation 3
The total mass is 53, giving the upper bound . Cut sets , , , and yield share masses , , , and . Hence and cuts are usable.
For each remaining cut , begin just after that cut and take the two shortest consecutive shares reaching mass 17. The remaining masses are respectively . Lengthening either earlier share cannot increase the final share. Thus none of these four cuts is usable in an optimal division, giving .