Alex_tz307

Fundamente XI - 7 / 219

Sep 21st, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define INF 0x3f3f3f3f
  3.  
  4. using namespace std;
  5.  
  6. inline void min_self(int& a, int b) {
  7.     a = min(a, b);
  8. }
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(nullptr);
  13.     cout.tie(nullptr);
  14.     int K, N;
  15.     cin >> K >> N;
  16.     vector < int > a(N);
  17.     for(int& x : a)
  18.         cin >> x;
  19.     vector < int > dp(16384, INF);
  20.     int index = 0;
  21.     dp[index] = 0;
  22.     while(dp[index] <= K) {
  23.         for(int x : a)
  24.             min_self(dp[index + x], dp[index] + 1);
  25.         ++index;
  26.     }
  27.     cout << index - 1;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment