Cod sursa(job #1819929)

Utilizator georgemihaiGeorge Mihai georgemihai Data 30 noiembrie 2016 23:28:51
Problema Secventa 2 Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include<fstream>
#include<iostream>
using namespace std;
ifstream in("secv2.in");
ofstream out("secv2.out");
int smax=-10000000000000,s,z,k,stot=-1,n,t,amax,bmax,a;
int main()
{
    in>>n>>z;
    for(int i=1;i<=n;i++)
    {
       in>>t;
       if(s<0)
       {
           s=t;
           k=1;
           a=i;
       }
       else
       {
        k++;
        s=s+t;
       }
       if(s>smax and k>z)
       {


           smax=s;
        amax=a;
        bmax=i;
       }
    }
    out<<amax<<" "<<bmax<<" "<<smax;
}