SHARE
TWEET

Gma Eaman

a guest Dec 11th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int t[1001][10001],i,j,gmax,n,g[10001],v[10001];
  4. int main()
  5. {
  6.     cin>>n>>gmax;
  7.     for(i=1;i<=n;i++)
  8.         cin>>g[i]>>v[i];
  9.     for(i=1;i<=n;i++){
  10.         for(j=1;j<=gmax;j++)
  11.             if(g[i]>j)
  12.             ///raduc
  13.             t[i][j]=t[i-1][j];
  14.         else t[i][j]=max(t[i-1][j],t[i-1][j-g[i]]+v[i]);
  15.     }
  16.     cout<<t[n][gmax];
  17.     return 0;
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top