fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<pair<int,string>> a;
  31.  
  32. pair<int,int> consistency(int n, int x, int y, int z){
  33.  
  34. vector<int> xx;
  35. vector<int> yy;
  36.  
  37. for(int i=0; i<n; i++){
  38. if(a[i].second == "USB") xx.push_back(a[i].first);
  39. else yy.push_back(a[i].first);
  40. }
  41.  
  42. sort(begin(xx), end(xx));
  43. sort(begin(yy), end(yy));
  44.  
  45.  
  46. int m = xx.size();
  47. n = yy.size();
  48.  
  49. int cost = 0;
  50. int ct = 0;
  51.  
  52. int i = 0;
  53. while(i<min(x,m)){
  54. cost += xx[i];
  55. ct++;
  56. i++;
  57. }
  58.  
  59. int j = 0;
  60. while(j<min(y,n)){
  61. cost += yy[j];
  62. ct++;
  63. j++;
  64. }
  65.  
  66. int k = 0;
  67. while(i<m && j<n && k<z){
  68. if(xx[i] < yy[j]){
  69. cost += xx[i];
  70. i++;
  71. }
  72. else {
  73. cost += yy[j];
  74. j++;
  75. }
  76. k++;
  77. }
  78.  
  79. while(i<m && k<z){
  80. cost += xx[i];
  81. i++;
  82. k++;
  83. }
  84. while(j<n && k<z){
  85. cost += yy[j];
  86. j++;
  87. k++;
  88. }
  89. ct += k;
  90.  
  91. return {ct, cost};
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. pair<int,int> practice(int n, int x, int y, int z){
  109.  
  110.  
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117. void solve() {
  118.  
  119. int x, y, z;
  120. cin>> x >> y >> z;
  121.  
  122. int n;
  123. cin >> n;
  124.  
  125. a.resize(n);
  126. for(int i=0; i<n; i++){
  127. int x;
  128. string s;
  129. cin >> x >> s;
  130. a[i] = {x, s};
  131. }
  132.  
  133. auto ans = consistency(n, x, y, z);
  134.  
  135. cout << ans.first << " " << ans.second << endl;
  136.  
  137.  
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144. int32_t main() {
  145. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  146.  
  147. int t = 1;
  148. // cin >> t;
  149. while (t--) {
  150. solve();
  151. }
  152.  
  153. return 0;
  154. }
Success #stdin #stdout 0s 5320KB
stdin
2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2
stdout
3 14