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; // Input number of test cases
  9. while (T--) {
  10. int n;
  11. cin >> n; // Number of rounds
  12. vector<int> s(n); // Scores for each round
  13. for (int i = 0; i < n; ++i) {
  14. cin >> s[i];
  15. }
  16.  
  17. // Sorting Alice's possible responses to maximize her wins
  18. int a, b, c;
  19. cin >> a >> b >> c;
  20.  
  21. // Alice's score options sorted in descending order
  22. vector<int> alice_scores = {a, b, c};
  23. sort(alice_scores.rbegin(), alice_scores.rend());
  24.  
  25. // Count Bob's scores
  26. vector<int> bob_scores(3, 0);
  27. for (int i = 0; i < n; ++i) {
  28. bob_scores[s[i]]++;
  29. }
  30.  
  31. int win_count = 0;
  32.  
  33. // Try to match Alice's scores against Bob's scores to maximize her wins
  34. for (int i = 0; i < 3; ++i) {
  35. for (int j = 0; j < 3; ++j) {
  36. if (alice_scores[i] > j && bob_scores[j] > 0) {
  37. win_count++;
  38. bob_scores[j]--;
  39. break;
  40. }
  41. }
  42. }
  43.  
  44. // Output the result
  45. cout << win_count << endl;
  46. }
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5316KB
stdin
3
5
01201
221
3
222
300
4
0122
112
stdout
0
3
3