Cod sursa(job #3322390)

Utilizator FistfullOfDollar059Andrei Marin Popa FistfullOfDollar059 Data 13 noiembrie 2025 19:00:28
Problema Secventa 2 Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.23 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	 ifstream fin("secv2.in");
    ofstream fout("secv2.out");
    
    int n, k;
    fin>>n>>k;
    vector<int> pref(n);
    pref[0] = 0;
    int current;
    for(int i = 0; i < n; i++){
        fin>>current;
        pref[i] = pref[i-1] + current;
    }
    
    int st = 0;
    int maxSum = -1e9;
    pair<int,int> indici;
    for(int dr = 0; dr < n; dr++){
        if(pref[dr] - pref[st-1] < 0){
            st = dr;
        }
        if(dr - st >=k && pref[dr] - pref[st-1] > maxSum){
            maxSum = max((pref[dr] - pref[st-1]), maxSum);
            indici.first = st+1;
            indici.second = dr+1;
        }
       // cout<<st<<" "<<dr<<"\n";
    }
    
    fout<<indici.first<<" "<<indici.second<<" "<<maxSum;

	return 0;
}