Josif_tepe

Untitled

Dec 9th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. const int INF = 2e9;
  8. int main() {
  9.     int b1, b2, b3;
  10.     cin >> b1 >> b2 >> b3;
  11.    
  12.     int M;
  13.     cin >> M;
  14.    
  15.     int najmala_razlika = INF;
  16.     int X, Y, Z;
  17.     for(int x = 0; x <= M; x++) {
  18.         for(int y = 0; y <= M; y++) {
  19.             for(int z = 0; z <= M; z++) {
  20.                 int sum = x*b1 + y*b2 + z*b3;
  21.                 if(sum <= M) {
  22. //                    cout << sum << endl;
  23.                     if(najmala_razlika > M - sum) {
  24.                         najmala_razlika = M - sum;
  25.                         X = x;
  26.                         Y = y;
  27.                         Z = z;
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.     }
  33.    
  34.     cout << najmala_razlika << endl;
  35.     cout << X << " " << Y << " " << Z << endl;
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment