Mai intai trebuie sa te autentifici.
Cod sursa(job #3162829)
| Utilizator | Data | 29 octombrie 2023 23:56:44 | |
|---|---|---|---|
| Problema | Economie | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.78 kb |
#include <bits/stdc++.h>
using namespace std;
const int VMAX = 5e4+2;
const int NMAX = 1e3+2;
int n,v[NMAX];
bitset<VMAX> dp;
ifstream fin("economie.in");
ofstream fout("economie.out");
int main()
{
fin >> n;
for(int i = 1; i <= n; i++){
fin >> v[i];
}
sort(v+1, v+n+1);
vector<int> ans;
dp[0] = 1;
for(int i = 1; i <= n; i++){
if(dp[v[i]] == 0){
ans.push_back(v[i]);
int pas = 1, add = VMAX/v[i];
while(add){
int coef = min(add, pas);
dp |= (dp<<(coef*v[i]));
add -= coef;
pas *= 2;
}
}
}
fout << ans.size() << "\n";
for(int it: ans){
fout << it << " ";
}
return 0;
}
