fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8.  
  9. int T;
  10. cin >> T;
  11. while (T--) {
  12. int n;
  13. cin >> n;
  14.  
  15. vector<int> s(n);
  16. int cnt0 = 0, cnt1 = 0, cnt2 = 0;
  17.  
  18. // 统计 Bob 的出拳数量
  19. for (int i = 0; i < n; ++i) {
  20. cin >> s[i];
  21. if (s[i] == 0) cnt0++;
  22. else if (s[i] == 1) cnt1++;
  23. else cnt2++;
  24. }
  25.  
  26. // Alice 的出拳数量
  27. int a, b, c;
  28. cin >> a >> b >> c;
  29.  
  30. int res = 0;
  31.  
  32. // 1. Alice 用 0 打 Bob 的 2
  33. int match = min(a, cnt2);
  34. res += match;
  35. a -= match;
  36. cnt2 -= match;
  37.  
  38. // 2. Alice 用 1 打 Bob 的 0
  39. match = min(b, cnt0);
  40. res += match;
  41. b -= match;
  42. cnt0 -= match;
  43.  
  44. // 3. Alice 用 2 打 Bob 的 1
  45. match = min(c, cnt1);
  46. res += match;
  47. c -= match;
  48. cnt1 -= match;
  49.  
  50. // 4. 剩余的 Alice 用 0 打 Bob 的 1
  51. match = min(a, cnt1);
  52. res += match;
  53. a -= match;
  54. cnt1 -= match;
  55.  
  56. // 5. 剩余的 Alice 用 1 打 Bob 的 2
  57. match = min(b, cnt2);
  58. res += match;
  59. b -= match;
  60. cnt2 -= match;
  61.  
  62. // 6. 剩余的 Alice 用 2 打 Bob 的 0
  63. match = min(c, cnt0);
  64. res += match;
  65.  
  66. cout << res << '\n';
  67. }
  68.  
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0s 5320KB
stdin
3
5
01201
221
3
222
300
4
0122
112
stdout
5
5
5