Pagini recente » Cod sursa (job #901728) | Cod sursa (job #3277560) | Cod sursa (job #1196007) | Cod sursa (job #2813613) | Cod sursa (job #2443988)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("economie.in");
ofstream g("economie.out");
int a[1005],b[50005];
int sol[1005];
int main()
{
int n;
f>>n;
int Max=0;
for(int i=1;i<=n;i++)
{
f>>a[i];
if(a[i]>Max)Max=a[i];
}
sort(a+1,a+n+1);
int k=0;
b[0]=1;
for(int i=1;i<=n;i++)
{
if(b[a[i]]==0)
{
sol[++k]=a[i];
for(int j=0;j<=Max-a[i];j++)
{
if(b[j]==1)
b[j+a[i]]=1;
}
}
}
g<<k<<'\n';
for(int i=1;i<=k;i++)
{
g<<sol[i]<<" ";
}
return 0;
}