Cod sursa(job #284902)

Utilizator dacyanMujdar Dacian dacyan Data 22 martie 2009 01:23:37
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
using namespace std;

long x, a, n, k;
long smax, s, i, j, imax , jmax;

int main()
{
    ifstream fin("secv2.in");
    fin >> n >> k;
    for ( i = 1; i <= n; i++)
    {
        fin >> x;
    
        s += x;
        if ( s >= 0) 
                a++;
        else 
        {
                a = 0;
                j = i;
                s = 0;
        }    
        if ( s > smax && a >= k)
        {
                jmax = j + 1;
                imax = i;
                smax = s;
        }    
         
    }
    fin.close();
    ofstream fout("secv2.out");
    fout  << jmax << ' ' << imax  << ' ' << smax << '\n';
    fout.close();
    return 0;
}