Josif_tepe

Untitled

Dec 9th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 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.             int sum = x*b1 + y*b2;
  20.             if(sum <= M) {
  21.                 int z = (M - sum) / b3;
  22.                 sum += z*b3;
  23.                
  24.                 if(sum <= M) {
  25.                     if(najmala_razlika > M - sum) {
  26.                         najmala_razlika = M - sum;
  27.                         X = x;
  28.                         Y = y;
  29.                         Z = z;
  30.                     }
  31.                 }
  32.             }
  33.            
  34.         }
  35.     }
  36.    
  37.     cout << najmala_razlika << endl;
  38.     cout << X << " " << Y << " " << Z << endl;
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment