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. // Alice's score options
  18. int a, b, c;
  19. cin >> a >> b >> c;
  20.  
  21. // Sort Alice's scores 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); // Bob's scores: 0, 1, 2
  27. for (int i = 0; i < n; ++i) {
  28. bob_scores[s[i]]++;
  29. }
  30.  
  31. int win_count = 0;
  32.  
  33. // 1. Try to use Alice's largest score to defeat Bob's smallest score
  34. // Alice's 0 beats Bob's 2, Alice's 1 beats Bob's 0, and Alice's 2 beats Bob's 1
  35. for (int i = 0; i < 3; ++i) {
  36. for (int j = 0; j < 3; ++j) {
  37. if (alice_scores[i] > j && bob_scores[j] > 0) {
  38. win_count++;
  39. bob_scores[j]--;
  40. break;
  41. }
  42. }
  43. }
  44.  
  45. // Output the result
  46. cout << win_count << endl;
  47. }
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5288KB
stdin
3
5
01201
221
3
222
300
4
0122
112
stdout
0
3
3