Pagini recente » Cod sursa (job #2589072) | Cod sursa (job #1547768) | Cod sursa (job #1143370) | Cod sursa (job #2443288) | Cod sursa (job #236676)
Cod sursa(job #236676)
#include <stdio.h>
int a[1005],sol[1005],s[50005];
int n,m;
int divide (int p,int q)
{
int st,dr,x;
st=p;
dr=q;
x=a[p];
while (st<dr)
{
while (st<dr && a[dr]>=x)
--dr;
a[st]=a[dr];
while (st<dr && a[st]<=x)
++st;
a[dr]=a[st];
a[st]=x;
}
return st;
}
void qsort (int p, int q)
{
int m;
m=divide (p,q);
if (m-1>p)
qsort (p,m-1);
if (m+1<q)
qsort (m+1,q);
}
void solve ()
{
int i,j;
if (a[1]==1)
{
printf ("1\n1");
return ;
}
else
for (i=1; i<=n; ++i)
if (!s[a[i]])
{
sol[++m]=a[i];
s[a[i]]=1;
for (j=1; j<=a[n]+1; ++j)
if (s[j])
s[j+a[i]]=1;
}
printf ("%d\n",m);
for (i=1; i<=m; ++i)
printf ("%d\n",sol[i]);
}
int main ()
{
freopen ("economie.in","r",stdin);
freopen ("economie.out","w",stdout);
int i;
scanf ("%d",&n);
for (i=1; i<=n; ++i)
scanf ("%d",&a[i]);
qsort (1,n);
solve ();
return 0;
}