Advertisement
Josif_tepe

Untitled

Mar 8th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int b1,b2,b3,pari;
  8.     cin>>b1>>b2>>b3>>pari;
  9.     int c1,c2,c3;
  10.     int a1,a2,a3;
  11.     int najmal_ostatok=100000000;
  12.     int end_i = pari  /b1;
  13.     int end_j = pari / b2;
  14.     for(int i = 0; i <= end_i; i++) {
  15.         c1 = i * b1;
  16.         if(c1 <= pari) {
  17.         for(int j = 0; j <= end_j; j++) {
  18.             c2 = j * b2;
  19.             if(c1 + c2 <= pari) {
  20.             int m = (pari - c1 - c2);
  21.             m /= b3;
  22.             c3 = m * b3;
  23.             if(c1 + c2 + c3 <= pari) {
  24.                 if(najmal_ostatok > pari - c1 - c2 - c3) {
  25.                     najmal_ostatok = pari - c1 - c2 -c3;
  26.                     a1 = i;
  27.                     a2 = j;
  28.                     a3 = m;
  29.                 }
  30.             }
  31.             }
  32.         }
  33.     }
  34.     }
  35.     cout<<najmal_ostatok<<endl;
  36.     cout<<a1<<" "<<a2<<" "<<a3<<endl;
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement