Pagini recente » Cod sursa (job #648856) | Cod sursa (job #2453007) | Cod sursa (job #1929921) | Cod sursa (job #442545) | Cod sursa (job #287975)
Cod sursa(job #287975)
#include <stdio.h>
int n,v[1001],t[50001],i,j,min;
void quick(int st, int dr)
{
int i=st,j=dr,p=(i+j)/2;
while (i<=j)
{
while (v[i]<v[p]) i++;
while (v[j]>v[p]) j--;
if (i<=j)
{
v[0]=v[i];
v[i]=v[j];
v[j]=v[0];
i++;
j--;
}
}
if (st<j) quick(st,j);
if (i<dr) quick(i,dr);
}
int main()
{
freopen("economie.in","r",stdin);
freopen("economie.out","w",stdout);
scanf("%d", &n);
for (i=1;i<=n;i++)
scanf("%d", &v[i]);
quick(1,n);
for (i=1;i<=n;i++)
{
if (t[v[i]]==0)
t[v[i]]=2, min++;
for (j=v[i]+1;j<=v[n];j++)
if (t[j-v[i]]>0)
t[j]=1;
}
printf("%d\n", min);
for (i=1;i<=v[n];i++)
if (t[i]==2)
printf("%d\n", i);
return 0;
}