Pagini recente » Cod sursa (job #741655) | Cod sursa (job #1125510) | Cod sursa (job #2477003) | Cod sursa (job #2346248) | Cod sursa (job #1204586)
#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],S;
int main() {
int i;
cin>>N>>K;
for(i=1;i<=N;i++)
cin>>V[i];
int max1=-100000,beg,end,max2=-100000;
if(N==K){
for(i=1;i<=N;i++)
S+=V[i];
cout<<1<<" "<<N<<" "<<S;
return 0;
}
S1[K-1]=0;
for(i=1;i<K;i++)
S1[K-1]=S1[i]+V[i];
for(i=K;i<=N;i++)
{
S1[i]=S1[i-1]+V[i];
if(max1<S1[i])
{
max1=S1[i];
end=i;
}
}
max2=max1;
S2[end+1]=0;
for(i=end;i>=1;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;
}