Pagini recente » Cod sursa (job #1719952) | Cod sursa (job #1251522) | Cod sursa (job #3168810) | Cod sursa (job #808395) | Cod sursa (job #1481705)
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1001],r[50001],i,j,k,n,c[1001];
int main() {
freopen("economie.in","r",stdin),freopen("economie.out","w",stdout),scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",a+i);
sort(a+1,a+n+1);
for(i=1;i<=n;i++) {
if(!r[a[i]])
c[++k]=a[i],r[a[i]]=a[i];
for(j=1;j<=50000-a[i];j++)
if(r[j]&&!r[j+a[i]])
r[j+a[i]]=j+a[i];
}
printf("%d\n",k);
for(i=1;i<=k;i++)
printf("%d\n",c[i]);
}