Cod sursa(job #3303437)

Utilizator Andrei-Dani-10Pisla Andrei Daniel Andrei-Dani-10 Data 15 iulie 2025 16:08:08
Problema Secventa 2 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>

using namespace std;

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

const int nmax = 50000;
int n, k, a[nmax + 2];

int bestt = -(1 << 30), st, dr, _st;

int main(){

    in>>n>>k;
    for(int i = 1; i <= n; i++)
        in>>a[i], a[i] += a[i - 1];

    for(int i = k; i <= n; i++){
        if(a[_st] > a[i - k])
            _st = i - k;
        if(bestt < a[i] - a[_st]){
            bestt = a[i] - a[_st];
            st = _st + 1;
            dr = i;
        }
    }

    out<<st<<" "<<dr<<" "<<bestt<<"\n";

    return 0;
}