Cod sursa(job #3236746)
Utilizator | Data | 1 iulie 2024 11:44:10 | |
---|---|---|---|
Problema | Secventa 2 | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.66 kb |
#include <fstream>
#include <climits>
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;
}