Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- +---------------------------------------------+
- | |
- | © 10/05/2024 (17:44) MinaMagdy |
- | |
- +---------------------------------------------+
- */
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
- #define multi_ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
- #define endl "\n"
- #define MOD 1000000007
- #define INF 2000000000
- #define all(s) s.begin(), s.end()
- #define rall(s) s.rbegin(), s.rend()
- #define sz(x) int(x.size())
- typedef long long ll;
- typedef long double ld;
- typedef unsigned long long ull;
- void solve() {
- int n, d;
- while (cin >> n >> d) {
- vector<int> v(d);
- for (auto& I : v)
- cin >> I;
- vector<int> ans;
- int diff = n;
- for (int i = 0; i < (1 << d); ++i) {
- int sum = 0;
- for (int j = 0; j < d; ++j) {
- if (i & (1 << j))
- sum += v[j];
- }
- if (sum <= n && diff > n - sum) {
- diff = n - sum;
- ans.clear();
- for (int j = 0; j < d; ++j) {
- if (i & (1 << j))
- ans.push_back(v[j]);
- }
- }
- }
- for (auto& I : ans)
- cout << I << " ";
- cout << "sum:" << n - diff << endl;
- }
- }
- int main(void)
- {
- ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
- int testcase = 1;
- // cin >> testcase;
- while (testcase--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement