Codeforces Round #193 (Div. 2) B. Maximum Absurdity

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.

Sample test(s)
input
5 2
3 6 1 1 6
output
1 4
input
6 2
1 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.



题目大意:就是求两段不相交的连续序列的和加起来最大,输出两个序列的左端位置。
思路:用RMQ 然后枚举做比较。被一个long long 坑出翔

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
typedef __int64 LL;
using namespace std;

LL f[300005][70];
LL Sum[300005]={0};
LL X[300005]={0};

int n,len;

void RMQINIT()
{
    for(int i=1;i<=n;i++)
    f[i][0]=X[i];

    for(int j=1;(1<<j)<=n;j++)
        for(int i=1;i+j-1<=n;i++)
            f[i][j]=max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
}

LL RMQ(int l,int r)
{
    int k=0;
    while((1<<(k+1))<=r-l+1)k++;
    return max(f[l][k],f[r+1-(1<<k)][k]);
}

int getj(LL xxx,int s)
{
    for(int j=s;j+len-1<=n;j++)
    if(X[j]==xxx)return j;
}

int main()
{
    scanf("%d%d",&n,&len);

    for(int i=1;i<=n;i++)
    {
        scanf("%I64d",&Sum[i]);
        Sum[i]=Sum[i-1]+Sum[i];
    }


    for(int i=1;i+len-1<=n;i++)
    {
        X[i]=Sum[i+len-1]-Sum[i-1];
    }

    RMQINIT();

    LL MAX=-1;
    LL ans1;
    LL ans2;
    

    for(int i=1;i+2*len-1<=n;i++)//注意只记录目标  而不是每次更新MAX的时候就去求位置 最后输出答案
    {					//而是只记录MAX  到最后才去找答案  可以少去好多不必要的操作
        LL lef=X[i];
        LL rig=RMQ(i+len,n-len+1);
        if(lef+rig > MAX)
        {
            MAX=lef+rig;
            ans1=lef;
            ans2=rig;
        }
    }
    //printf("ans1 = %I64d\n",ans1);

    int pos1=getj(ans1,1);

    //printf("pos1 = %d\n",pos1);

    int pos2=getj(ans2,pos1+len);

    printf("%d %d\n",pos1,pos2);

    return 0;
}



/*

50 20
723279347 595451630 134184940 699776757 892203439 863188688
414672911 933526083 488345578 549966859 895128043 735880119
630679289 849472800 544225599 345468807 595489241 387150921
365335832 650967361 175584626 164326586 123110153 659307279
640551894 561724386 979925106 740146933 228299649 470768296
831323579 994604559 660896408 629829807 528990615 327336918
444972076 455842708 684599364 607435097 494268278 581327404
209071303 722962566 669518106 361107913 72801330 695757664
209919078 682357108

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值