Alex_tz307

School-CCC Snack Vendor - Level 2

Oct 28th, 2020 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("text.in");
  6. ofstream fout("text.out");
  7.  
  8. int main() {
  9.     int price, N;
  10.     fin >> price >> N;
  11.     vector < int > a(N);
  12.     int sum = 0;
  13.     for(int& x : a) {
  14.         fin >> x;
  15.         sum += x;
  16.     }
  17.     if(price > sum)
  18.         fout << "MISSING " << price - sum;
  19.     else {
  20.         int ans = sum - price;
  21.         fout << "CHANGE ";
  22.         vector < int > sol(8), coins{1, 2, 5, 10, 20, 50, 100, 200};
  23.         for(int i = 7; i >= 0; --i) {
  24.             int cnt = ans / coins[i];
  25.             ans -= cnt * coins[i];
  26.             sol[i] = cnt;
  27.         }
  28.         for(int x : sol)
  29.             fout << x << ' ';
  30.     }
  31. }
  32.  
Add Comment
Please, Sign In to add comment