Codeforces Problem 332B

来源:互联网 发布:社会网络分析大数据 编辑:程序博客网 时间:2024/05/22 14:35

B. Maximum Absurdity
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

This time mr. Boosch plans to sign 2k 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 ab(1 ≤ a ≤ b ≤ n - k + 1, b - a ≥ k) and sign all laws with numbers lying in the segments [aa + k - 1] and [bb + k - 1] (borders are included).

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.

Input

The first line contains two integers n and k (2 ≤ n ≤ 2·1050 < 2k ≤ 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 x1, x2, ..., xn — the absurdity of each law (1 ≤ xi ≤ 109).

Output

Print two integers ab — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [aa + k - 1] and [bb + 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.

Examples
input
5 23 6 1 1 6
output
1 4
input
6 21 1 1 1 1 1
output
1 3
Note

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.

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.


题意:有n个数,找两个不相交的长度为k的连续子区间,使得两子区间内元素和为最大


思路:现对得到的数据进行处理,求出以每个位置为结尾的长度为k的区间和,以及在该点之后最大的区间和及其位置,再进行遍历


#include<iostream>#include<string.h>#include<stdio.h>using namespace std;#define LL long longconst int maxn = 2 * 1e5 +100;LL n,k,a[maxn],sum[maxn],mx[maxn],pos[maxn],i;int main(){    scanf("%lld%lld",&n,&k);    for(i=1;i<=n;i++){        scanf("%lld",&a[i]);        sum[i] = sum[i-1] + a[i];        if(i>=k) sum[i] -= a[i-k];    }    for(i=n;i>=k;i--){        if(sum[i]>=mx[i+1]){            mx[i] = sum[i];            pos[i] = i;        }        else{            mx[i] = mx[i+1];            pos[i] = pos[i+1];        }    }    LL ans = 0,pos1 = 0,pos2 = 0;    for(i=k;i<=n;i++){        LL sm = sum[i] + mx[i+k];        if(ans<sm){            ans = sm;            pos1 = i-k+1;            pos2 = pos[i+k]-k+1;        }    }    printf("%lld %lld\n",pos1,pos2);    return 0;}



原创粉丝点击