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; // Read the number of test cases
  9.  
  10. while (T--) {
  11. int n;
  12. cin >> n; // Read the number of rounds
  13.  
  14. vector<int> counts(3, 0); // To count the occurrences of 0, 1, and 2
  15.  
  16. for (int i = 0; i < n; i++) {
  17. int s;
  18. cin >> s; // Read each round result
  19. counts[s]++;
  20. }
  21.  
  22. int a, b, c;
  23. cin >> a >> b >> c; // Read Alice's move restrictions
  24.  
  25. // Find the optimal number of wins Alice can have
  26. int max_wins = min(counts[0], a) + min(counts[1], b) + min(counts[2], c);
  27.  
  28. cout << max_wins << endl; // Output the maximum wins Alice can have
  29. }
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 5284KB
stdin
3
5
0 1 2 0 1
2 2 1
3
2 2 2
3 2 2
4
1 2 2 0
1 1 1
stdout
5
2
3