Pagini recente » Cod sursa (job #1170711) | Cod sursa (job #1132650) | Cod sursa (job #136172) | Cod sursa (job #1490713) | Cod sursa (job #984158)
Cod sursa(job #984158)
#include <iostream>
#include <fstream>
#include <climits>
#define nmax 6000005
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int n,v[nmax],dp[nmax],maxim,pozi,s,i,pozf=1;
int main()
{
in >> n;
for (int i=1; i<=n; i++) in >> v[i];
dp[n]=v[n];
maxim=-INT_MAX;
pozi=n;
for (int i=n-1; i>=1; i--) {
dp[i]=max(v[i], dp[i+1]+v[i]);
if (dp[i]>maxim){
maxim=dp[i];
pozi=i;
}
}
i=pozi;
s=maxim;
while (s) s-=v[i++];
if (i-1>0) pozf=i-1;
else pozf=1;
out << maxim << " " << pozi << " " << pozf;
return 0;
}