Cod sursa(job #2513593)

Utilizator hurjui12AlexandruHurjui Alexandru-Mihai hurjui12Alexandru Data 23 decembrie 2019 14:43:07
Problema Secventa 2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <queue>
using namespace std;

ifstream fin("alfa.in");
ofstream fout("alfa.out");

int main()
{
    queue <int> q;
    int i, n, x, k, smax, lgs, fmax, s;
    fin >> n >> k;
    s = 0;
    for (i = 1; i<=k; i++)
    {
        fin >> x;
        q.push(x);
        s = s + x;
    }
    smax = s;
    lgs = k;
    fmax = k;
    for (i = k+1; i<=n; i++)
    {
        fin >> x;
        if (q.front() > 0)
            s = s + x;
        else
        {
            s = s - q.front() + x;
            q.pop();
        }
        q.push(x);
        if (s > smax)
        {
            smax = s;
            lgs = q.size();
            fmax = i;
        }
    }
    fout << fmax - lgs+1 << ' ' << fmax << ' ' << smax;
    return 0;
}