Pagini recente » Cod sursa (job #2057834) | Cod sursa (job #673410) | Cod sursa (job #1284981) | Cod sursa (job #823839) | Cod sursa (job #998334)
Cod sursa(job #998334)
#include <cstdlib>
#include <vector>
#include <algorithm>
const int MAX_N(1005);
const int MAX_VALUE(50005);
int n;
int v [MAX_N];
bool Mark [MAX_VALUE];
std::vector<int> Result;
inline void Read (void)
{
std::freopen("economie.in","r",stdin);
std::scanf("%d",&n);
for (int i(1) ; i <= n ; ++i)
std::scanf("%d",&v[i]);
std::fclose(stdin);
}
inline void Print (void)
{
std::freopen("economie.out","w",stdout);
std::printf("%d\n",static_cast<int>(Result.size()));
for (auto it : Result)
std::printf("%d\n",it);
std::fclose(stdout);
}
inline void Greedy (void)
{
Mark[0] = true;
std::sort(v + 1,v + n + 1);
int i, j, end;
for (i = 1 ; i <= n ; ++i)
if (!Mark[v[i]])
{
Result.push_back(v[i]);
for (j = 0, end = v[n] - v[j] ; j <= end ; ++j)
if (Mark[j])
Mark[j + v[i]] = true;
}
}
int main (void)
{
Read();
Greedy();
Print();
return 0;
}