Cod sursa(job #2394893)

Utilizator mihnea.anghelMihnea Anghel mihnea.anghel Data 2 aprilie 2019 08:36:53
Problema Economie Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <algorithm>

using namespace std;
ifstream f("economie.in");
ofstream g("economie.out");
int d[51000], n, maxi, i,v[1100],j, rez[1100], k;
int main()
{
    f>>n;
    for(i=1;i<=n;i++){
        f>>v[i];
        maxi=max(maxi,v[i]);
    }
    sort(v+1,v+n+1);
    d[0]=1;
    for(i=1;i<=n;i++)
        if(d[v[i]]==0){
            rez[++k]=v[i];
            for(j=0; j<=maxi-v[i]; j++)
                if(d[j]==1)
                    d[j+v[i]]=1;
        }
    g<<k<<"\n";
    for(i=1;i<=k;i++) g<<v[i]<<" ";
    return 0;
}