Cod sursa(job #2169306)

Utilizator Luca19Hritcu Luca Luca19 Data 14 martie 2018 14:43:19
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

using namespace std;
int a[50000],n,i,max1=-100000000,s=-1,x,k,pozi,pozmax,pozmax1,t;
int main()
{
    ifstream f("secv2.in");
    ofstream g("secv2.out");
    f>>n>>x;
for(i=1;i<=n;i++)
{
    f>>t;
    if(s<0)
    {
        s=t;
        k=1;
        pozi=i;
    }
    else
    {
        k++;
        s=s+t;
    }
 if(s>max1&&k>x)
     {
        max1=s;
        pozmax=pozi;
        pozmax1=i;
    }
}

g<<pozmax<<" "<<pozmax1<<" "<<max1;

    return 0;
}