Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <algorithm>
- int N;
- int V, low=5000, ans=0, menu[5000];
- void run(int coins, int mask)
- {
- if(coins < 0) return;
- if(coins < low)
- {
- low = coins;
- ans = mask;
- }
- for(int i=0; i<N; i++)
- {
- if(!(mask & (1 << i)))
- run(coins-menu[i], mask | (1 << i));
- }
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- std::cin >> N >> V;
- for(int i=0; i<N; i++)
- std::cin >> menu[i];
- run(V, 0);
- for(int i=0; i<N; i++)
- {
- if(ans & (1 << i))
- std::cout << menu[i] << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment