Pagini recente » Cod sursa (job #2040341) | Cod sursa (job #2456744) | Cod sursa (job #2076339) | Cod sursa (job #1986479) | Cod sursa (job #903476)
Cod sursa(job #903476)
#include<iostream>
#include<fstream>
using namespace std;
ofstream g("ssm.out");
ifstream f("ssm.in");
#define NMAX 6000001
int a[NMAX], best[NMAX] = {0};
void solutie(int bestSum, int i){
if(i > 0 && bestSum){
solutie(bestSum - a[i], i-1);
g << a[i] << " ";
}
}
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;
}
}
solutie(bestSum,bestPoz);
f.close();
g << "\n";
g.close();
}