Pagini recente » Cod sursa (job #2761693) | Cod sursa (job #3240365) | wow-ce-poate-fi-asa-de-smecher | Cod sursa (job #2963410) | Cod sursa (job #288012)
Cod sursa(job #288012)
#include<stdio.h>
#define NMAX 1000
int n,i,j,ok,k,v[NMAX],t[50*NMAX],max;
void quick(int st, int dr)
{
int i=st,j=dr;
int p;
p=v[(i+j)/2];
if(i>j) return;
while (i<=j)
{
while(v[i]<p) i++;
while(v[j]>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[i]=2;
k++;
}
for(j=v[i];j<=v[n];j++)
if(t[j-v[i]]>0){
t[j]=1;
}
}
printf("%d\n", k);
for(i=1;i<=v[n];i++)
if(t[i]==2) printf("%d\n", i);
return 0;
}