Cod sursa(job #2986520)

Utilizator StefannnnnStefan Stefannnnn Data 28 februarie 2023 18:30:37
Problema Economie Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <vector>
#define maximum 50001

using namespace std;

ifstream cin("economie.in");
ofstream cout("economie.out");

bool able_to_make[maximum];
vector<int> v, answer;

int main() {
    int n;
    cin >> n;
    v.resize(n);
    for(int i = 0; i < n; i ++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    able_to_make[0] = 1;
    for(int i = 0; i < n; i ++) {
        if(able_to_make[v[i]] == false) {
            answer.push_back(v[i]);
            for(int j = 0; j + v[i] < maximum; j ++) {
                if(able_to_make[j] == true) {
                    able_to_make[j + v[i]] = true;
                }
            }
        }
    }
    cout << answer.size() << '\n';
    for(int number : answer) {
        cout << number << '\n';
    }
}