Cod sursa(job #2712563)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 25 februarie 2021 23:13:58
Problema Economie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("economie.in");
ofstream fout("economie.out");

const int NMAX = 1024;
const int VMAX = 5e4 + 4;
int N, a[NMAX];
bitset<VMAX> dp;
vector<int> sol;

int main() {
    fin >> N;
    for(int i = 1; i <= N; ++i)
        fin >> a[i];
    sort(a + 1, a + N + 1);
    dp[0] = true;
    for(int i = 1; i <= N; ++i)
        if(!dp[a[i]]) {
            sol.emplace_back(a[i]);
            for(int j = 0; j + a[i] < VMAX; ++j)
                if(dp[j])
                    dp[j + a[i]] = true;
        }
    fout << sol.size() << '\n';
    for(const int &x : sol)
        fout << x << '\n';
}