PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000484. Chia bánh (Cake Division)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chia bánh (Cake Division)

Cake Division

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A round cake has been divided into NN pieces by radial cut lines from its center to its circumference. Both pieces and cut lines are numbered clockwise from 11 to NN. Piece ii has mass AiA_i.

Cut line ii separates pieces ii and i+1i+1, with cut line NN separating piece NN from piece 11. Clockwise order therefore wraps from piece NN to piece 11.

Divide the entire cake among KK 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 wiw_i be the total mass received by person ii. A division is optimal if its value of min⁡(w1,w2,…,wK)\min(w_1,w_2,\ldots,w_K) 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 min⁡(w1,w2,…,wK)\min(w_1,w_2,\ldots,w_K) and the number of cut lines that are unused in every optimal division.

Input

The first line contains two integers N,KN,K, the number of pieces and the number of recipients.

The second line contains NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N, the masses of the pieces in clockwise order starting at piece 1.

Output

Print two integers x,yx,y on one line, separated by a space. Here xx is the largest possible minimum share mass, and yy counts the cut lines absent from every optimal division.

Subtasks

  • Subtask 1 (20 points): 2≤K≤N≤162\le K\le N\le 16; 1≤Ai≤1041\le A_i\le 10^4 for every 1≤i≤N1\le i\le N; all input values are integers.

  • Subtask 2 (30 points): 2≤K≤N≤20002\le K\le N\le 2000; 1≤Ai≤1041\le A_i\le 10^4 for every 1≤i≤N1\le i\le N; all input values are integers.

  • Subtask 3 (50 points): 2≤K≤N≤2000002\le K\le N\le 200000; 1≤Ai≤1041\le A_i\le 10^4 for every 1≤i≤N1\le i\le N; 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 6+8=146+8=14 and 6+4+3=136+4+3=13. Cuts 2 and 4 give masses 8+6=148+6=14 and 4+3+6=134+3+6=13. Thus x=13x=13, 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 3,9,17,233,9,17,23, none of which equals 13 or 14. Thus only cut 5 is absent from every optimal division, giving y=1y=1.

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 (2,3,5)(2,3,5), (2,3,6)(2,3,6), and (2,4,6)(2,4,6) give masses (11,12,13)(11,12,13), (11,14,11)(11,14,11), and (14,11,11)(14,11,11), respectively. Thus x=11x=11, 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 y=1y=1.

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 ⌊53/3⌋=17\lfloor53/3\rfloor=17. Cut sets (1,3,6)(1,3,6), (1,3,7)(1,3,7), (1,4,7)(1,4,7), and (3,6,10)(3,6,10) yield share masses (17,17,19)(17,17,19), (17,18,18)(17,18,18), (18,17,18)(18,17,18), and (17,17,19)(17,17,19). Hence x=17x=17 and cuts 1,3,4,6,7,101,3,4,6,7,10 are usable.

For each remaining cut 2,5,8,92,5,8,9, begin just after that cut and take the two shortest consecutive shares reaching mass 17. The remaining masses are respectively 11,16,4,911,16,4,9. Lengthening either earlier share cannot increase the final share. Thus none of these four cuts is usable in an optimal division, giving y=4y=4.