Advertisement
Josif_tepe

Untitled

Mar 14th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int b1, b2, b3, m;
  7.     cin >> b1 >> b2 >> b3 >> m;
  8.     int najmal_kusur = m;
  9.     int X, Y, Z;
  10.     for(int x = 0; x <= m / b1; x++) {
  11.         for(int y = 0; y <= m / b2; y++) {
  12.             for(int z = 0; z <= m / b3; z++) {
  13.                 if(x * b1 + y * b2 + z * b3 <= m) {
  14.                     if(najmal_kusur > m - (x * b1 + y * b2 + z * b3)) {
  15.                         najmal_kusur = m - (x * b1 + y * b2 + z * b3);
  16.                         X = x;
  17.                         Y = y;
  18.                         Z = z;
  19.                     }
  20.                 }
  21.             }
  22.         }
  23.     }
  24.     cout << najmal_kusur << endl;
  25.     cout << X << " " << Y << " " << Z << endl;
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement