Advertisement
Josif_tepe

Untitled

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