Advertisement
Josif_tepe

Untitled

Mar 11th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int b1,b2,b3,m,x,y,z,min=200000000,a1,a2,a3;
  7. cin>>b1>>b2>>b3>>m;
  8.  
  9. for(x=0;x<=m;x++){
  10.     for(y=0;y<=m;y++){
  11.         int kupeno = x * b1 + y * b2;
  12.         if(kupeno > m) continue;
  13.             z = m - kupeno;
  14.             z /= b3;
  15.            
  16.             int vkupno = x * b1 + y * b2 + z * b3;
  17.             if(vkupno <= m and m - vkupno < min) {
  18.                 min = m - vkupno;
  19.                 a1 = x;
  20.                 a2 = y;
  21.                 a3 = z;
  22.             }
  23.         }
  24. }
  25.  
  26. cout<<min<<endl;
  27. cout<<a1<<" "<<a2<<" "<<a3<<endl;
  28.  
  29.  
  30.  
  31.  
  32. return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement