Advertisement
Josif_tepe

Untitled

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