Cod sursa(job #1847533)

Utilizator savigunFeleaga Dragos-George savigun Data 14 ianuarie 2017 18:22:05
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
#include <fstream>
using namespace std;

struct {
    int s, l = 1;
} best[50001];

int main()
{
    ifstream cin("secv2.in");
    ofstream cout("secv2.out");
    int n, i, k, nr, pmax, smax = 0;
    cin>>n>>k;
    best[0].s = -1;

    for(i = 1; i <= n; ++i) {
        cin>>nr;
        if(nr > nr + best[i-1].s) {
            best[i].s = nr;
        } else {
            best[i].s = nr + best[i-1].s;
            best[i].l = best[i-1].l + 1;

            if (best[i].l >= k && best[i].s > smax) {
                smax = best[i].s;
                pmax = i;
            }
        }
    }

    cout<<pmax - best[pmax].l + 1<<" "<<pmax<<" "<best[pmax].s;

    return 0;
}