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 = m;
- int X, Y, Z;
- for(int x = 0; x <= m / b1; x++) {
- for(int y = 0; y <= m / b2; y++) {
- int momentalno = x * b1 + y * b2;
- momentalno = m - momentalno;
- int z = momentalno / b3;
- if(x * b1 + y * b2 + z * b3 <= m) {
- if(najmal_kusur > m - (x * b1 + y * b2 + z * b3)) {
- najmal_kusur = m - (x * b1 + y * b2 + z * b3);
- X = x;
- Y = y;
- Z = z;
- }
- }
- }
- }
- cout << najmal_kusur << endl;
- cout << X << " " << Y << " " << Z << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement