Cod sursa(job #2010650)

Utilizator shantih1Alex S Hill shantih1 Data 13 august 2017 22:57:04
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin("secv2.in");
ofstream fout("secv2.out");

long long n, i, j, k, l, mx, best[50005], a, b, x;

int main () {
    
    fin >> n >> k;
    fin >> j;
    best[1] = j;
    mx = best[1];
    a = 1; b = 1;
    x = 1;
    for (i = 2; i <= n; i++)
    {
        fin >> j;
        if (best[i-1]+j > j)
            best[i] = best[i-1]+j;
        
        else
        {
            best[i] = j;
            x = i;
        }
        
        if (best[i] > mx && i-x+1 >= k)
        {
            mx = best[i];
            a = x;  b = i;
        }
    }
    
    fout << a << " " << b << " " << mx << "\n";
}