Cod sursa(job #1401799)

Utilizator MastaronKatona Aron Mastaron Data 26 martie 2015 09:51:56
Problema Secventa 2 Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream f ("secv2.in");
    ofstream g ("secv2.out");
    int n,k,a[50001],o=0,e,u;
    f>>n>>k;
    for(int i=1;i<=n;i++)
    {
        int ot=0, h=0;
        f>>a[i];
        for(int j=i;j>=1;j--)
        {
            ot+=a[j];
            h++;
            if(h>=k && ot>o)
            {
                o=ot;
                e=i;
                u=j;
            }
        }
    }
    g<<u<<" "<<e<<" "<<o;
    f.close();
    g.close();
    return 0;
}