Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long lli;
- const int N = 10;
- int price[N + 10], value[N + 10];
- int main(){
- int nItem, money;
- scanf("%d%d", &nItem, &money);
- for(int i = 0; i < nItem; ++i){
- scanf("%d%d", &price[i], &value[i]);
- }
- lli mx = 0;
- for(int i = 1; i < (1 << nItem); ++i){
- lli sumPrice = 0;
- lli sumValue = 0;
- for(int j = 0; j < nItem; ++j){
- if((i & (1 << j)) != 0){
- sumPrice += price[j];
- sumValue += value[j];
- if(sumPrice > money){
- break;
- }
- }
- }
- if(sumPrice <= money){
- mx = max(mx, sumValue);
- }
- }
- cout << mx;
- return 0;
- }
Add Comment
Please, Sign In to add comment