Cod sursa(job #1566840)

Utilizator horatiuchevalHoratiu Cheval horatiucheval Data 12 ianuarie 2016 17:55:27
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>
using namespace std;

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

    int n, k, x, sc = 0, smax = -2000000000, st = 1, stmax = 1, drmax = 1;
    fin>>n>>k;
    for(int i = 1; i <= n; i++){
        fin>>x;

        if(sc < 0){
            st = i;
            sc = 0;
        }
        sc += x;

        if(sc > smax){
            stmax = st;
            drmax = i;
            if(drmax - stmax >= k){
                smax = sc;
            }
        }
    }

    fout<<stmax<<" "<<drmax<<" "<<smax;
    fin.close();
    fout.close();
    return 0;
}