Cod sursa(job #2813415)

Utilizator andreea_chivuAndreea Chivu andreea_chivu Data 6 decembrie 2021 16:23:28
Problema Secventa 2 Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include  <fstream>

using namespace std;

#define INF 20000000000

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

    long long n, k;
    fin >> n >> k;

    long long sc = -1;
    long long smax = -INF;
    long long st = 1;
    long long stmax, drmax;
    long long lc = 0;

    for(long long i = 1; i <= n; i++){
        long long x;
        fin >> x;
        if(sc < 0){
            sc = x;
            st = i;
            lc = 1;
        }else{
            sc+=x;
            lc++;
        }
        if(lc >= k && sc > smax){
            smax = sc;
            stmax = st;
            drmax = i;
        }
    }

    fout << stmax << " " << drmax << " " << smax;

    fin.close();
    fout.close();
    return 0;
}