fork download
  1. #include<bits/stdc++.h>
  2. #define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
  3. using namespace std;
  4.  
  5. const int mxn=2e5+5,mod=1e9+7;
  6.  
  7. int main(void){
  8. fast;
  9. int n,m,i,j;
  10. cin>>n>>m;
  11. string s[n];
  12. char t[n];
  13. int sw[n],p[n];
  14. for(i=0;i<n;i++)
  15. cin>>s[i]>>t[i]>>sw[i]>>p[i];
  16. int dp[n+1][m+1][2];
  17. memset(dp,0,sizeof dp);
  18. for(i=0;i<n;i++){
  19. for(j=1;j<=m;j++){
  20. if(t[i]=='S'){
  21. if(sw[i]<=j){
  22. dp[i+1][j][0]=max(dp[i][j][0],dp[i][j-sw[i]][0]+p[i]);
  23. dp[i+1][j][1]=max({dp[i][j][1],dp[i][j-sw[i]][1]+p[i],dp[i][j-sw[i]/2][0]+p[i]});
  24. }
  25. else if(sw[i]/2<=j){
  26. dp[i+1][j][1]=max(dp[i][j-sw[i]/2][0]+p[i],dp[i][j][1]);
  27. dp[i+1][j][0]=dp[i][j][0];
  28. }
  29. else{
  30. dp[i+1][j][0]=dp[i][j][0];
  31. dp[i+1][j][1]=dp[i][j][1];
  32. }
  33.  
  34. }
  35. else{
  36. dp[i+1][j][0]=dp[i][j][0];
  37. dp[i+1][j][1]=dp[i][j][1];
  38. }
  39. }
  40. }
  41. cout<<max(dp[n][m][0],dp[n][m][1]);
  42. }
  43.  
Success #stdin #stdout 0.01s 5320KB
stdin
4 4
dairymilk S 5 15
kitkat H 7 10
fivestar S 2 20
snickers S 4 17
stdout
37