Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- //#include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- int b1, b2, b3, m;
- cin >> b1 >> b2 >> b3 >> m;
- int najmal_kusur = 2e9;
- int X = 0, Y = 0, Z = 0;
- for(int x = 0; x <= m / b1; x++) {
- for(int y = 0; y <= m / b2; y++) {
- int sum = m - (x * b1 + y * b2);
- int z = sum / b3;
- int sum2 = x * b1 + y * b2 + z * b3;
- if(sum2 <= m) {
- if(najmal_kusur > m - sum2) {
- najmal_kusur = m - sum2;
- X = x;
- Y = y;
- Z = z;
- }
- }
- }
- }
- cout << najmal_kusur << endl;
- cout << X << " " << Y << " " << Z << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement