Cod sursa(job #1769160)
| Utilizator | Data | 1 octombrie 2016 23:23:03 | |
|---|---|---|---|
| Problema | Secventa 2 | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.03 kb |
#include <iostream>
#include <fstream>
using namespace std;
int a[6000001];
int main()
{
ifstream in("secv2.in");
ofstream out("secv2.out");
int i,sc,smax,x,y,n,xc=1,lung=1,k,b=-10000000;
in>>n>>k;
for(i=1; i<=n; i++)
in>>a[i];
sc = smax = a[1];
for (i=2; i<=n; i++)
{
if(sc<0)
if (sc < b)
{
sc=0;
xc=i;
lung=0;
}
else
if (sc < b )
{
b=sc;
sc=0;
xc=i;
lung=0;
}
sc =sc + a[i];
lung++;
if(sc>0)
if (sc > smax && lung>=k)
{
smax = sc;
x = xc;
y=i;
}
if(sc<0)
if (sc < smax && lung>=k)
{
smax = sc;
x = xc;
y=i;
}
out<<sc<<" "<<smax<<" "<<b<<endl;
}
out<<x<<" "<<y<<" "<<smax;
return 0;
}
