Cod sursa(job #2155358)
| Utilizator | Data | 7 martie 2018 20:11:04 | |
|---|---|---|---|
| Problema | Secventa 2 | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.52 kb |
#include <fstream>
using namespace std;
ifstream f("secv2.in");
ofstream g("secv2.out");
long long n,j,i,smax,pi,stot,s,x,st,dr,k;
const long long MX=1250000000;
int main()
{
f>>n>>k;
smax=0-MX; pi=1; stot=0; s=0;
for(i=1;i<=n;i++){
f>>x;
if(s<0) { s=0; pi=i; }
s+=x; stot+=x;
if(i-pi+1>=k&&s>smax){
smax=s;
st=pi; dr=i;
}
}
if(k==n) g<<1<<' '<<n<<' '<<stot<<'\n';
else g<<st<<' '<<dr<<' '<<smax<<'\n';
return 0;
}
