题目描述

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·105, 0 < 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 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.


题意:在一段长度为n的数列中,选择两端不重叠的,长度为k的序列,使他们的和最大。

解析:一开始看到这个题,萌生了一个弱智的想法——没错就是线段树。一开始想的是用前缀和,表示从第i个数开始,向后数k个数的和,然后枚举左边以k为长度的区间,再用线段树求出右边不重合部分的最大值。但是后来,仔细一想,好像根本不需要这么做,只要从前往后,一边维护前面不重合部分的最大,一边枚举右边长度为k的最大就可以直接求出答案了。但是由于时间原因,第二份代码我还没有写,所以就只能贴出来第一种想法的代码了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[400010];
long long sum[400010];
long long cnt[400010];
int n,k;
struct Edge{int l,r;long long maxx;
}tr[5000000];
void build(int d,int l,int r){tr[d].l=l,tr[d].r=r;if(l==r){tr[d].maxx=cnt[l];return ;}int ls=d*2,rs=d*2+1;int mid=(l+r)/2;build(ls,l,mid);build(rs,mid+1,r);tr[d].maxx=max(tr[ls].maxx,tr[rs].maxx);return ;
}
long long querry(int d,int l,int r){int ll=tr[d].l,rr=tr[d].r;
//  printf("%d %d %d %d %d\n",d,ll,rr,l,r);if(r==rr&&l==ll){return tr[d].maxx;}int ls=d*2,rs=d*2+1;int mid=(ll+rr)/2;if(mid>=r){return querry(ls,l,r);}else if(mid<l){return querry(rs,l,r);}else {return max(querry(ls,l,mid),querry(rs,mid+1,r));}
}
int main(){cin>>n>>k;for(int i=1;i<=n;i++){scanf("%I64d",&a[i]);}for(int i=1;i<=n;i++){sum[i]=sum[i-1]+a[i];}for(int i=1;i<=n;i++){cnt[i]=sum[i+k-1]-sum[i-1];}long long ans_max=0;long long ans_a=0;long long ans_b=0;build(1,1,n-k+1);for(int i=1;i<=n-2*k+2;i++){int l=i,r=i+k-1;long long temp=cnt[l];int rr=n-k+1;if(rr>=r+1)temp+=querry(1,r+1,n-k+1);if(temp>ans_max){ans_max=temp;ans_a=i;ans_b=temp-cnt[l];}}cout<<ans_a<<" ";for(int i=ans_a+k;i<=n-k+1;i++){if(ans_b==cnt[i]){cout<<i<<endl;return 0;}}return 0;
}

Maximum Absurdity相关推荐

  1. 【CodeForces 332B --- Maximum Absurdity】递推

    [CodeForces 332B --- Maximum Absurdity]递推 题目来源:点击进入[CodeForces 332B - Maximum Absurdity] Description ...

  2. [CodeForces 332B]Maximum Absurdity[DP]

    题目链接: [CodeForces 332B]Maximum Absurdity[DP] 题意分析: 寻找两个不重叠的长度为k的子串,使得它们之和最大. 解题思路: 第一想法是,处理出从这个点开始,长 ...

  3. Maximum Absurdity(dp思想+前缀和)

    Maximum Absurdity 原题目:Maximum Absurdity 题解 处理长度为 k 的区间和用前缀和 处理不相交的两个区间和用 dp 思想,以 i 为界线,用四个数组分别记录位置 i ...

  4. codeforces332B - Maximum Absurdity 线段数 or dp

    题意:给你一个序列,找两个长度为 k 且没有重合区间的数使得其和最大 解题思路: 1)线段树 想了半天想不出只能先用线段树撸了一发,这题dp 第一名只要了 9分钟. 就是把起点为 i  长度为 k 的 ...

  5. CodeForces - 332B  Maximum Absurdity   前缀和

    这道题主要用的前缀和的思想,看了网上大佬的代码感觉很巧妙.我之前有好几个点没注意,WA了好几次,还有就是要用long long类型.不多说了,直接贴AC代码: #include<cstdio&g ...

  6. CodeForces 332B Maximum Absurdity

    http://codeforces.com/problemset/problem/332/B 给出n个数,再个一个长度,问在n个数的数列中,找到2个相应长度的数串求和最大,且这两个数串不能重叠.只要对 ...

  7. Codeforces 332B Maximum Absurdity(暴力)

    题意: 给你一个序列,让你在里面选择两个不想交的长度为k的字段,是的和最大. 我第一次做还是用的dp,感觉复杂度有点高啊,后来发现直接预处理就好了. 预处理需要三个数组,分别是sum[i],Max[i ...

  8. CodeForces 332B Maximum Absurdity(线段树单点更新)

    题意: 给你一个序列,找两个长度为 k 且没有重合区间的数使得其和最大 解析: 线段树,就是把起点为 i 长度为 k 的和预处理出来,再枚举a,与a线段不重合的,后面的部分用线段树来找最大位置,总复杂 ...

  9. codeforce 332B Maximum Absurdity

    原题链接 题意 一个长为N的序列,选择其中2个长为K的不相交区间,使两个区间和最大 题解 CF标签上写的好好的DP,做着做着发现就是前缀和思想嘛,哪里有DP?哪里有DP? #include<bi ...

最新文章

  1. TensorFlow 2.0发布在即,高级API变化抢先看
  2. 同样是AI技术,为什么只有一加6称得上“全速”旗舰?
  3. 安全、稳定、可靠甲骨文定义PaaS新时代
  4. FPGA/IC Technology Exchange
  5. 【PAT (Advanced Level) Practice】1051 Pop Sequence (25 分)
  6. cocos2x (c++/lua) spine 文件的预加载
  7. 使用Def文件导出dll
  8. 怎么用程序实现调用Android手机的拍照功能
  9. SqlServer2008 R2 自动备份和自动清除过期备份
  10. oracle _db_block_write_batch,Oracle体系结构----实例的进程结构
  11. DuiLib教程--认识她
  12. 计算机编程方面的电子书大汇总 阿里云盘
  13. matlab安装自行下载的工具箱
  14. Js实现继承的6种方式
  15. matlab求系统根轨迹代码_第九讲? 根轨迹法
  16. Pixhawk学习9——固定翼位置控制(L1控制+TECS总能量控制)
  17. 使用ROS melodic下 控制真实UR5机器人 手把手教程
  18. 正则表达式基本语法总结
  19. Windows上安装Linux
  20. Linux中文件搜索,查找,读取

热门文章

  1. [经验分享] 覃超线上直播课 如何快速搞定秋招算法面试
  2. 百度地图框选标注坐标返回标注信息
  3. 【Trie图】Hiho4_Hihocoder
  4. 使用SQL Server管理数据表
  5. excel文件被写保护怎么解除_excel撤销写保护的教程
  6. Java中出现[Ljava.lang.String的问题
  7. B-样条基函数:重要性质
  8. PHP之流程控制(四)
  9. 年仅21岁,干掉6位诺贝尔奖得主,被誉为科学界最强杀手,却惨被人骂成一个笑话...
  10. Mac版本Unity如何设置中文