Pagini recente » Cod sursa (job #235212) | Cod sursa (job #1179808) | Cod sursa (job #41515) | Cod sursa (job #2193539) | Cod sursa (job #903468)
Cod sursa(job #903468)
#include<iostream>
#include<fstream>
using namespace std;
void solutie(int bestSum, int a[], int best[], int i){
if(i > 0 && bestSum){
solutie(bestSum - a[i], a, best, i-1);
cout << a[i] << " ";
}
}
int main(){
ifstream f("date.in");
int i, n, a[100], best[100]={0}, 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,a,best,bestPoz);
/*for(i = bestPoz; i > 0 && bestSum; i--){
if(bestSum == best[i]){
cout << a[i] << " ";
bestSum = bestSum - a[i];
}
}*/
}