Iamtui1010

atm.cpp

Sep 19th, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<map>
  4. #include<algorithm>
  5.  
  6. #define long long long
  7. #define nln '\n'
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     //cin.tie(0)->sync_with_stdio(0);
  14.     //freopen("atm.inp", "r", stdin);
  15.     vector<long> mon{1, 5, 10, 50, 100, 500};
  16.     map<long, long> qlt;
  17.     for (auto i : mon)
  18.         cin >> qlt[i];
  19.     long x;
  20.     cin >> x;
  21.  
  22.     long cnt = 0;
  23.     while (x && mon.size()){
  24.         long num = min(x/mon.back(), qlt[mon.back()]);
  25.         cnt += num;
  26.         x -= num*mon.back();
  27.         mon.pop_back();
  28.     }
  29.  
  30.     if (x)
  31.         cout << -1 << nln;
  32.     else
  33.         cout << cnt << nln;
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment