Cod sursa(job #2909142)

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

int maxx = -25005, countt, 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 && countt >= k) {
            maxx = act;
            rightt = i;
        }
        if (act < 0) {
            act = 0;
            countt = 0;
            leftt = i;
        }
    }
    fout << leftt << ' ' << rightt << ' ' << maxx;
    return 0;
}