Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<fstream>
- #include<vector>
- #include<algorithm>
- #define long long long
- #define nln '\n'
- const long N = 20;
- using namespace std;
- // GLobal variables: cow, m, n
- fstream f1,f2;
- inline void openf()
- {
- f1.open("vcowflix.inp", ios:: in);
- f2.open("vcowflix.out", ios:: out);
- }
- inline void closef()
- {
- f1.close();
- f2.close();
- }
- long m, n;
- vector<long> cow;
- void data()
- {
- f1.tie(0)->sync_with_stdio(0);
- f2.tie(0)->sync_with_stdio(0);
- cin.tie(0)->sync_with_stdio(0);
- cin >> m >> n;
- for (long i = 0; i != n; ++i)
- {
- long x;
- cin >> x;
- cow.push_back(x);
- }
- }
- long mav = 0, sum;
- vector<bool> ava;
- void carry(long i)
- {
- if (i == n)
- {
- if (sum <= m && sum > mav)
- mav = sum;
- return;
- }
- if (ava[i])
- {
- sum += cow[i];
- ava[i] = 0;
- carry(i+1);
- ava[i] = 1;
- }
- sum -= cow[i];
- carry(i+1);
- }
- void process()
- {
- ava.resize(n, 1);
- carry(0);
- }
- void view()
- {
- cout << mav << nln;
- }
- int main()
- {
- openf();
- data();
- process();
- view();
- closef();
- return 0;
- }
Add Comment
Please, Sign In to add comment