Cod sursa(job #1889669)

Utilizator Luca19Hritcu Luca Luca19 Data 22 februarie 2017 20:31:03
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.4 kb
#include <fstream>

using namespace std;
int a[1000],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;
}