Advertisement
Josif_tepe

Untitled

Mar 15th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <map>
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9. int main()
  10. {
  11.     int b1, b2, b3, m;
  12.     cin >> b1 >> b2 >> b3 >> m;
  13.     int najmal_kusur = m;
  14.     int k1 = -1, k2 = -1, k3= -1;
  15.     for(int x = 0;  x <= m / b1; x++) {
  16.         for(int y = 0; y <= m / b2; y++) {
  17.             int suma = x * b1 + y * b2;
  18.             suma = m - suma;
  19.             suma /= b3;
  20.             if(x * b1 + y * b2 + suma * b3 <= m) {
  21.                 if(najmal_kusur > m - (x * b1 + y * b2 + suma * b3)) {
  22.                     najmal_kusur = m - (x * b1 + y * b2 + suma * b3);
  23.                     k1 = x;
  24.                     k2 = y;
  25.                     k3 = suma;
  26.                 }
  27.             }
  28.         }
  29.     }
  30.     cout << najmal_kusur << endl;
  31.     cout << k1 << " " << k2 << " " << k3 << endl;
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement