Cod sursa(job #1231428)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 20 septembrie 2014 16:28:43
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#define Inf 0x3f3f3f3f

using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
long n,i,i2,j2,j3,mx,x,s=-1,ji,ii,ok,k;
int main()
{

    f>>n;
    f>>k;
    mx=-Inf;
    for(i=1;i<=n;i++)
    {
        f>>x;
        if(s < x)
            {s=s+x; ok=0;}
        else
            {   s=s+x;
            if(s<=-1){
                    if(s>mx)
                    {
                        mx=s;
                        ji=i;
                        i2=ii;
                        ok=1;
                    }
                    s=0; ii=i;}

                }
        if(s>mx&&ok==0)
        {   if(ji-(i2+1)>=k)
            {mx=s;
            ji=i;
            i2=ii;}
            else
            {
                ji=i;
            i2=ii;
            }
        }
    }
   g<<i2+1<<" "<<ji<<" "<<mx;

    return 0;
}