Advertisement
Alex_tz307

IOIT coin change

Dec 15th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. int32_t main() {
  7.     ios_base::sync_with_stdio(false);
  8.     cin.tie(nullptr);
  9.     cout.tie(nullptr);
  10.     vector<int> prices{1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000};
  11.     int sum = 0;
  12.     for(int i = 0; i < 15; ++i) {
  13.         int x;
  14.         cin >> x;
  15.         sum += x * prices[i];
  16.     }
  17.     vector<int> sol(15);
  18.     int p = 14;
  19.     while(p >= 0) {
  20.         sol[p] = sum / prices[p];
  21.         sum %= prices[p];
  22.         --p;
  23.     }
  24.     for(int x : sol)
  25.         cout << x << ' ';
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement