Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int b1,b2,b3,m,x,y,z,min=200000000,a1,a2,a3;
- cin>>b1>>b2>>b3>>m;
- for(x=0;x<=m;x++){
- for(y=0;y<=m;y++){
- int kupeno = x * b1 + y * b2;
- if(kupeno > m) continue;
- z = m - kupeno;
- z /= b3;
- int vkupno = x * b1 + y * b2 + z * b3;
- if(vkupno <= m and m - vkupno < min) {
- min = m - vkupno;
- a1 = x;
- a2 = y;
- a3 = z;
- }
- }
- }
- cout<<min<<endl;
- cout<<a1<<" "<<a2<<" "<<a3<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement