Cod sursa(job #153627)

Utilizator alexeiIacob Radu alexei Data 10 martie 2008 17:21:56
Problema Economie Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<stdio.h>
#include<algorithm>
using namespace std;

#define nmax 50002
#define nmic 1001
int a[nmax],sol[nmic],nr[nmic];

int main()
{
 freopen("economie.in","r",stdin);
 freopen("economie.out","w",stdout);
 
 int n,max=0,i,j;
 scanf("%d",&n);
 
 
 for(i=1; i<=n; ++i){
          scanf("%d",&nr[i]);   
          if(max<nr[i])
          max=nr[i];}
 
 sort(nr+1,nr+1+n);
 
int nrsol=0,val; 
 
 a[0]=1;
 
 for(i=1; i<=n; ++i){
          
          if( !a[i] ){       
          ++nrsol;
          sol[nrsol]=nr[i];
          val=nr[i];
          
          for(j=1; j<=max; ++j)
                   if(a[j-val] == 1 || !j%val)
                   a[j]=1;
          
          }
}
    
    printf("%d\n",nrsol);
    
    for(i=1; i<=nrsol; ++i)
    printf("%d\n",sol[i]);
    
    return 0;
}