Pagini recente » Cod sursa (job #1384468) | Cod sursa (job #3268976) | Cod sursa (job #1271124) | Cod sursa (job #2272495) | Cod sursa (job #903491)
Cod sursa(job #903491)
#include<iostream>
#include<fstream>
using namespace std;
ofstream g("ssm.out");
ifstream f("ssm.in");
#define NMAX 6000001
int a[NMAX], best[NMAX] = {0};
int main(){
int i, n, bestSum, bestPoz = 1;
f >> n;
for(i = 1; i <= n; i ++){
f >> a[i];
}
bestSum = a[1];
for(i = 1; i <= n; i ++){
best[i] = a[i];
if(best[i] < best[i-1] + a[i])
best[i] = best[i-1] + a[i];
if(bestSum < best[i]){
bestSum = best[i];
bestPoz = i;
}
}
cout << bestSum;
for(i = bestPoz; i > 0 && bestSum; i --){
if(bestSum == best[i]) bestSum -= a[i];
}
g << bestSum << " " << i << " " << bestPoz << "\n";
f.close();
g.close();
}