Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- typedef long long ll;
- const int INF = 2e9;
- int main() {
- int b1, b2, b3;
- cin >> b1 >> b2 >> b3;
- int M;
- cin >> M;
- int najmala_razlika = INF;
- int X, Y, Z;
- for(int x = 0; x <= M; x++) {
- for(int y = 0; y <= M; y++) {
- for(int z = 0; z <= M; z++) {
- int sum = x*b1 + y*b2 + z*b3;
- if(sum <= M) {
- // cout << sum << endl;
- if(najmala_razlika > M - sum) {
- najmala_razlika = M - sum;
- X = x;
- Y = y;
- Z = z;
- }
- }
- }
- }
- }
- cout << najmala_razlika << endl;
- cout << X << " " << Y << " " << Z << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment