Cod sursa(job #2643012)

Utilizator cyg_dawidDavid Ghiberdic cyg_dawid Data 18 august 2020 12:24:12
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <fstream>
#include <algorithm>

#define ll long long
using namespace std;

ll n, mmax = -1250000010, last, x, y, st, dr, provisory_st, k;

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

int main()
{
    fin >> n >> k;
    last = 0; st = dr = provisory_st = 1;
    for(int i = 1; i <= n; i++) {
        fin >> x;
        y = last;
        last = max(last + x, x);
        if(last == x && y != 0) {
            provisory_st = i;
        }
        if(last > mmax && i - provisory_st + 1 >= k) {
            mmax = last;
            dr = i; st = provisory_st;
        }
    }
    fout << st << " " << dr << " " << mmax;
    return 0;
}