Cod sursa(job #1204570)

Utilizator pavlov.ionPavlov Ion pavlov.ion Data 3 iulie 2014 13:00:59
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<fstream>
using namespace std;
#define MAXN 50001
ifstream cin("secv2.in");
ofstream cout("secv2.out");
int V[MAXN],N,K,S1[MAXN],S2[MAXN];
int main() {
	int i;
	cin>>N>>K;
	for(i=1;i<=N;i++)
	          cin>>V[i];
	int max1=-100000,beg,end,max2=-100000;
	for(i=K;i<=N;i++)
	{
	    S1[i]=S1[i-1]+V[i];
		if(max1<S1[i])
		{
		         max1=S1[i];
		         end=i;
	     }         
	 }
	max2=max1;
	for(i=end;i>=K;i--)
	{
			S2[i]=S2[i+1]+V[i];
			if(max2<S2[i])
			{
			    max2=S2[i];
				beg=i;
				}
    }
    cout<<beg<<" "<<end<<" ";
    if(max1>max2) cout<<max1;
        else cout<<max2;
       return 0; 
		}