Advertisement
Josif_tepe

Untitled

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