Pagini recente » Cod sursa (job #2770077) | Cod sursa (job #2691559) | Cod sursa (job #1950684) | Cod sursa (job #2459670) | Cod sursa (job #3236745)
#include <fstream>
using namespace std;
ifstream cin ("secv2.in");
ofstream cout ("secv2.out");
struct{
long long d,p;
}d[50002];
long long n,k,i,a,s[50002];
long long r,p1,p2,p,sum;
int main() {
cin>>n>>k;
for(i=1;i<=n;i++){
cin>>a;
s[i]=s[i-1]+a;
if(sum<1){
sum=0;
p=i;
}
sum+=a;
d[i]={sum,p};
}
r=INT_MIN;
for(i=k;i<=n;i++) {
sum=s[i]-s[i-k+1]+d[i-k+1].d;
if(r<sum){
r=sum;
p1=d[i-k+1].p;
p2=i;
}
}
cout<<p1<< ' ' <<p2<< ' ' <<r;
return 0;
}