Cod sursa(job #2909043)

Utilizator alexdvResiga Alexandru alexdv Data 8 iunie 2022 12:33:30
Problema Secventa 2 Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
using namespace std;

int maxx = -25005, first_pos, last_pos, act, n, k, v[50001], leftt, rightt;

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