Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define ll long long
- #define pb push_back
- #define mp make_pair
- int n, c;
- vector<pair<int, int>> weight;
- int dp[100][30000];
- int rec(int idx, int w){
- if(idx == c) return 0;
- if(dp[idx][w] != -1){
- return dp[idx][w];
- }
- int result = -2e9;
- result = max(result, rec(idx + 1, w));
- if(weight[idx].second <= w){
- result = max(result, rec(idx + 1, w - weight[idx].second + weight[idx].first) + 1);
- }
- dp[idx][w] = result;
- return result;
- }
- int main(){
- ios_base::sync_with_stdio(false);
- cout.tie(0);
- cin.tie(0);
- cin >> n >> c;
- for(int i = 0; i < c; i++){
- int a, b;
- cin >> a >> b;
- weight.pb(mp(b, a));
- }
- sort(weight.rbegin(), weight.rend());
- for(int i = 0; i < c; i++){
- for(int j = 0; j < 30000; j++){
- dp[i][j] = -1;
- }
- }
- cout << rec(0, n) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement