Cod sursa(job #2643015)

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

#define ll long long
using namespace std;

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

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

int main()
{
    fin >> n >> k;
    last = 0; provisory_st = 1;
    for(int i = 1; i <= n; i++) {
        fin >> x; s += 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;
            st = provisory_st; dr = i;
        }
    }
    if(s > mmax)
        fout << "1 " << n << " " << s;
    else
        fout << st << " " << dr << " " << mmax;
    return 0;
}