Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- #define ll long long
- #define cy cout << "YES"
- #define cn cout << "NO"
- #define nl "\n"
- #define fi first
- #define se second
- #define cin(v) for (int i = 0; i < n, cin >> v[i]; i++)
- #define cout(v) for (int i = 0; i < v.size(), cout << v[i] << " "; i++)
- #define all(v) v.begin(), v.end()
- #define sz(s) s.size()
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- ll n , w;
- vector < pair < ll, ll> >v;
- map < ll , ll >mp;
- ll rec(ll i , ll j){
- if(j == 0 || i == n - 1) return 0;
- if(j < 0 || i >= n) return 1e9;
- ll& ret = mp[i];
- if(mp.find(ret) != mp.end()) return ret;
- ret = min(rec(i + 1 , j) , rec(i + 1 , j - v[i].se) + v[i].fi);
- return ret;
- }
- void solve(){
- cin >> n >> w;
- v.resize(n);
- for(int i = 0 ; i < n ; i++)
- cin >> v[i].fi >> v[i].se;
- for(int i = 1e5 ; i >= 0 ; i--){
- if(rec(0 , i) <= w){
- return void(cout << i << nl);
- }
- }
- }
- int main()
- {
- sherry();
- int t = 1;
- // cin >> t;
- while (t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement