Cod sursa(job #1769162)
Utilizator | Ciorica Vlad vladboss2323 | Data | 1 octombrie 2016 23:26:19 |
---|---|---|---|
Problema | Secventa 2 | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.97 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 < 0 )
{
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<<x<<" "<<y<<" "<<smax;
return 0;
}