fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int c,d,n,ans = 0;
  4. char cc;
  5. int pro,cost;
  6. const int MAX = 2e5+7;
  7. //Learnt this concept from no of strictly increasing subarrays...
  8. //Didn't get this idea though myself...
  9.  
  10. vector<vector<int> > tree(2*MAX,vector<int>(2,0));
  11.  
  12. void update(int row,int idx,int val)
  13. {
  14. //fuk one line update beech....
  15. for(;idx<=MAX;idx+=(idx&-idx)) tree[idx][row] = max(tree[idx][row],val);
  16. }
  17.  
  18. int query(int row,int idx)
  19. {
  20. int res = 0;
  21. for(;idx>0;idx-=(idx&-idx)) res = max(res,tree[idx][row]);
  22. return res;
  23. }
  24.  
  25. int main(int argc, char const *argv[]) {
  26. ios_base::sync_with_stdio(false);
  27. cin.tie(0); cout.tie(0);
  28. cin>>n>>c>>d;
  29. //0 for coins and 1 for diamonds
  30. for(int i=1;i<=n;i++)
  31. {
  32. cin>>pro>>cost>>cc;
  33. if(cc=='C')
  34. {
  35. int m1 = query(1,d),m2=0;
  36. if(c-cost>=0) m2 = query(0,c-cost);
  37. if(max(m1,m2)>0) ans = max(ans,max(m1,m2)+pro);
  38. update(0,cost,pro);
  39. }else
  40. {
  41. int m1 = query(0,c),m2=0;
  42. if(d-cost>=0) m2 = query(1,d-cost);
  43. if(max(m1,m2)>0) ans = max(ans,max(m1,m2)+pro);
  44. update(1,cost,pro);
  45. }
  46. }
  47. std::cout <<ans<< '\n';
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.02s 24800KB
stdin
3 10 10
5 5 C
5 5 C
10 11 D
stdout
15