Pagini recente » Cod sursa (job #1199613) | Cod sursa (job #718081) | Cod sursa (job #1934203) | Cod sursa (job #2192194) | Cod sursa (job #984120)
Cod sursa(job #984120)
#include <iostream>
#include <fstream>
#define nmax 6000005
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int n,v[nmax],dp[nmax],maxim,pozi,s,i;
int main()
{
in >> n;
for (int i=1; i<=n; i++) in >> v[i];
dp[n]=v[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++];
cout << maxim << " " << pozi << " " << i-1;
return 0;
}