Advertisement
Ahmed_Negm

Untitled

Jan 21st, 2023
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define OO 2'000'000'000
  8. #define ull unsigned long long
  9. #define nl '\n'
  10. #define sz(x) (ll)(x.size())
  11. #define all(x) x.begin(),x.end()
  12. #define rall(s)  s.rbegin(), s.rend()
  13. #define getline(s) getline(cin>>ws,s)
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. #define pi  3.141592653589793
  16. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  17. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  18.  
  19.  
  20. void Fast_IO(){
  21. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  22. // freopen("filename.in", "r", stdin);
  23. // freopen("filename.txt", "w", stdout);
  24. #ifndef ONLINE_JUDGE
  25. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28.  
  29. int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  30. int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  31.  
  32. map<ll,ll>mp;
  33.  
  34. ll dp[55][100005];
  35. ll n;
  36. vector<ll>v;
  37. ll rec(ll idx,ll x){
  38.   if(x==0) return 1;
  39.   if(x<0) return 0;
  40.   ll &ret = dp[idx][x];
  41.   if(ret!=-1)return ret;
  42.   ret = 0;
  43.   for(int i=idx;i<n;i++){
  44.     if(x-v[i]>=0 and mp[v[i]]){
  45.       mp[v[i]]--;
  46.       ret|=rec(i,x-v[i]);
  47.       mp[v[i]]++;
  48.     }
  49.   }
  50.   return ret;
  51. }
  52.  
  53.  
  54. void solve(){
  55.   ll x; cin>>n>>x;
  56.       v = vector<ll>(n);
  57.   for(int i=0;i<n;i++){
  58.     cin>>v[i];
  59.     ll t; cin>>t;
  60.     mp[v[i]] = t;
  61.   }
  62.   memset(dp,-1,sizeof(dp));
  63.   if(rec(0,x))cout<<"Yes"<<nl;
  64.   else cout<<"No"<<nl;
  65.  
  66.  
  67.  
  68.  
  69. }
  70.  
  71. int main(){
  72.     Fast_IO();
  73. int t =1;
  74. //cin>>t;
  75. while(t--){
  76. solve();
  77. }
  78. return 0;
  79. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement