Cod sursa(job #672584)

Utilizator costin7856Antonesi Florean Costin costin7856 Data 2 februarie 2012 16:44:04
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
#define dim 50001
using namespace std;
int n,i,sc,a[dim],smax=-1000000,k,st,stmax,drmax;
int main()
{
    ifstream f("secv2.in");
    ofstream g("secv2.out");
    f>>n>>k;
    for(i=1;i<=n;i++)
		f>>a[i];
    for(i=k;i<=n;i++)
    {
        if(sc<=0)
        {
            st=i;
            sc=a[i];
        }
        else
			sc+=a[i];
        if(sc>smax)
        {
            smax=sc;
            stmax=st;
            drmax=i;
        }
    }
    g<<stmax<<" "<<drmax<<" "<<smax ;
}