Cod sursa(job #1640961)

Utilizator lflorin29Florin Laiu lflorin29 Data 8 martie 2016 20:06:49
Problema Economie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1024;
const int MAX_SUM = 50007;

int N , A[MAX_N];
bool oke[MAX_SUM];

void read()
{
   freopen("economie.in", "r", stdin);
   scanf("%d", &N);
   for(int i = 1 ; i <= N ; ++i)
        scanf("%d", A + i);
}

void solve()
{
  freopen("economie.out", "w", stdout);
  sort(A + 1 , A + N + 1);
  vector<int>ans;
  for(int i = 1 ; i <= N ; ++i)
    {
         if(oke[A[i]] == false)
            ans.push_back(A[i]);
         oke[A[i]] = 1;
         for(int s = 1 ; s + A[i] < MAX_SUM ; ++s)
            oke[s + A[i]] |= oke[s];
    }

    printf("%d\n", ans.size());
    for(const int &res : ans)
        printf("%d ", res);

}

int main()
{
    read();
    solve();
    return 0;
}