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