Cod sursa(job #2092457)
Utilizator | Data | 21 decembrie 2017 18:24:35 | |
---|---|---|---|
Problema | Secventa 2 | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");
long long s,mx=INT_MIN;
int i,x,j,v[50005],n,k,p=1,u,all,pg,ug;
int main()
{
fin>>n>>k;
for (i=1; i<=n; i++)
{
fin>>x;
if (s>=0)
s+=x;
else
{
s=x;
p=i;
}
if (s>mx && i-p+1>=k)
{
ug=i;
mx=s;
pg=p;
}
all+=x;
}
if (k==n) fout<<"1 "<<n<<all;
else fout<<pg<<" "<<ug<<" "<<mx;
return 0;
}