Cod sursa(job #2909146)

Utilizator alexdvResiga Alexandru alexdv Data 9 iunie 2022 16:59:52
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <fstream>
using namespace std;

int maxx = -25005, countt, last_left, act, n, k, v[50001], leftt = 1, rightt = 1;

int main() {
    ifstream fin("secv2.in");
    ofstream fout("secv2.out");
    fin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        fin >> v[i];
    }
    for (int i = 1; i <= n; ++i) {
        act = act + v[i];
        ++countt;
        if (countt == 1) {
    		leftt = i;
    	}
        if (maxx < act) {
            maxx = act;
            rightt = i;
            last_left = leftt;
        }
        if (act < 0) {
            act = 0;
            countt = 0;
        }
    }
    if (rightt - last_left >= k) {
    	fout << last_left << ' ' << rightt << ' ' << maxx;
    } else {
    	fout << 0 << ' ' << 0 << ' ' << 0;
    }
    return 0;
}