Cod sursa(job #1767153)
Utilizator | Data | 28 septembrie 2016 19:14:26 | |
---|---|---|---|
Problema | Secventa 2 | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.62 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,lung=0,k;
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)
{
sc = 0;
xc=i;
lung=0;
}
sc += a[i];
lung++;
if (sc > smax && lung>=k)
{
smax = sc;
x = xc;
y=i;
}
}
out<<x<<" "<<y<<" "<<smax;
return 0;
}