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,pari;
- cin>>b1>>b2>>b3>>pari;
- int c1,c2,c3;
- int a1,a2,a3;
- int najmal_ostatok=100000000;
- int end_i = pari /b1;
- int end_j = pari / b2;
- for(int i = 0; i <= end_i; i++) {
- c1 = i * b1;
- if(c1 <= pari) {
- for(int j = 0; j <= end_j; j++) {
- c2 = j * b2;
- if(c1 + c2 <= pari) {
- int m = (pari - c1 - c2);
- m /= b3;
- c3 = m * b3;
- if(c1 + c2 + c3 <= pari) {
- if(najmal_ostatok > pari - c1 - c2 - c3) {
- najmal_ostatok = pari - c1 - c2 -c3;
- a1 = i;
- a2 = j;
- a3 = m;
- }
- }
- }
- }
- }
- }
- cout<<najmal_ostatok<<endl;
- cout<<a1<<" "<<a2<<" "<<a3<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement