Pagini recente » Cod sursa (job #2814568) | Cod sursa (job #938056) | Cod sursa (job #574440) | Cod sursa (job #466475) | Cod sursa (job #1204580)
#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;
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;
}