Pagini recente » Cod sursa (job #2748665) | sada | Cod sursa (job #1156901) | Cod sursa (job #2273382) | Cod sursa (job #247503)
Cod sursa(job #247503)
#include<algorithm>
using namespace std;
int n,k,a[50001];
void solve(){
int i,j,st,dr,pozst,pozdr,max=-25000;
scanf("%d%d",&n,&k);
for(i=1; i<=n; ++i){
scanf("%d",&a[i]);
a[i]+=a[i-1];}
for(st=0,dr=k; st+k<n+2&&dr<=n; ++dr)
if(a[dr]-a[st]<0)
++st;
else if(a[dr]-a[st]>max&&st+k<n+2){
max=a[dr]-a[st];
pozst=st+1;
pozdr=dr;}
printf("%d %d %d",pozst,pozdr,max);}
int main(){
freopen("secv2.in","r",stdin);
freopen("secv2.out","w",stdout);
solve();
return 0;}