tuki2501

vcowflix.cpp

Nov 7th, 2021
1,254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.   cin.tie(0)->sync_with_stdio(0);
  6.   int c, n;
  7.   cin >> c >> n;
  8.   vector<int> a(n);
  9.   for (auto &i : a) cin >> i;
  10.   int ans = 0;
  11.   for (int mask = 0; mask < (1 << n); mask++) {
  12.     int sum = 0;
  13.     for (int i = 0; i < n; i++) {
  14.       if ((mask >> i) & 1) sum += a[i];
  15.     }
  16.     if (sum <= c) ans = max(ans, sum);
  17.   }
  18.   cout << ans << '\n';
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment