332B.md (2589B)
1 Source: https://codeforces.com/problemset/problem/332/B 2 3 B. Maximum Absurdity 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed. 22 23 This time mr. Boosch plans to sign 2*k* laws. He decided to choose exactly two non-intersecting segments of integers from 1 to *n* of length *k* and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers *a*, *b* (1 ≤ *a* ≤ *b* ≤ *n* - *k* + 1, *b* - *a* ≥ *k*) and sign all laws with numbers lying in the segments [*a*; *a* + *k* - 1] and [*b*; *b* + *k* - 1] (borders are included). 24 25 As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him. 26 27 Input 28 29 The first line contains two integers *n* and *k* (2 ≤ *n* ≤ 2·105, 0 < 2*k* ≤ *n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1, *x*2, ..., *x**n* — the absurdity of each law (1 ≤ *x**i* ≤ 109). 30 31 Output 32 33 Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a* + *k* - 1] and [*b*; *b* + *k* - 1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple solutions, print the one with the minimum *b*. 34 35 Examples 36 37 Input 38 39 ``` 40 5 2 41 3 6 1 1 6 42 ``` 43 44 Output 45 46 ``` 47 1 4 48 ``` 49 50 Input 51 52 ``` 53 6 2 54 1 1 1 1 1 1 55 ``` 56 57 Output 58 59 ``` 60 1 3 61 ``` 62 63 Note 64 65 In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16. 66 67 In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.