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;
- cin >> b1 >> b2 >> b3 >> m;
- int najmal_kusur = 2e9;
- int k1, k2, k3;
- for(int x = 0; x <= m; x++) {
- for(int y = 0; y <= m; y++) {
- int vkupno = x * b1 + y * b2;
- if(vkupno <= m) {
- int z = m - vkupno;
- z /= b3;
- vkupno += z * b3;
- if(vkupno <= m) {
- if(m - vkupno < najmal_kusur) {
- najmal_kusur = m - vkupno;
- k1 = x;
- k2 = y;
- k3 = z;
- }
- }
- }
- }
- }
- cout << najmal_kusur << endl;
- cout << k1 << " " << k2 << " " << k3 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement