Cod sursa(job #2068550)
| Utilizator | Data | 18 noiembrie 2017 09:04:35 | |
|---|---|---|---|
| Problema | Secventa 2 | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 kb |
#include <iostream>
#include <climits>
#include <fstream>
using namespace std;
ifstream fin ("secv2.in");
ofstream fout ("secv2.out");
int n,k,i,x,maxx = INT_MIN,st,stf,drf;
long long s,stot;
int main()
{
fin >> n >> k;
for(i=1; i<=n; i++)
{
fin >> x;
if(s<0)
{
s=x;
st=i;
}
else
s=s+x;
if(s>maxx && i-st+1>=k)
{
stf=st;
drf=i;
maxx=s;
}
stot+=x;
}
if(k==n)
fout << 1 << " " << n << " " << stot;
else
{
fout << stf << " " << drf << " " << maxx ;
}
return 0;
}
