Pagini recente » Clasament r2-2023 | Cod sursa (job #2296920) | Cod sursa (job #2032047) | Cod sursa (job #2677964) | Cod sursa (job #1204564)
#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=1;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>=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;
}