Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- int main()
- {
- int b1, b2, b3, m;
- cin >> b1 >> b2 >> b3 >> m;
- int najmal_kusur = 2e9;
- int X, Y, Z;
- for(int x = 0; x <= m; x++) {
- if(x * b1 > m) continue;
- for(int y = 0; y <= m; y++) {
- if(x * b1 + y * b2 > m) continue;
- int bonboni1 = x * b1;
- int bonboni2 = y * b2;
- int z = m - bonboni1 - bonboni2;
- z /= b3;
- int bonboni3 = z * b3;
- if(bonboni1 + bonboni2 + bonboni3 > m) continue;
- if(najmal_kusur > m - (bonboni1 + bonboni2 + bonboni3)) {
- najmal_kusur = m - (bonboni1 + bonboni2 + bonboni3);
- 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