Cod sursa(job #2713058)

Utilizator tomaionutIDorando tomaionut Data 27 februarie 2021 10:29:23
Problema Economie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("economie.in");
ofstream fout("economie.out");
int n, a[1005],b[50005],sol[1005],k;
int main()
{	
	int i, j;
	fin >> n;
	for (i = 1; i <= n; i++)
		fin >> a[i];
	sort(a + 1, a + n + 1);
	b[0] = 1;
	for (i=1; i<=n; i++)
		if (b[a[i]] == 0)
		{
			sol[++k] = a[i];
			for (j = 0; j + a[i] <= 50000; j++)
				if (b[j] == 1)
					b[j + a[i]] = 1;
		}
	fout << k << "\n";
	for (i = 1; i <= k; i++)
		fout << sol[i] << "\n";
	return 0;
}