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.  
  10. while (T--) {
  11. int n;
  12. cin >> n;
  13.  
  14. vector<int> bob(n);
  15. for (int i = 0; i < n; i++) {
  16. char ch;
  17. cin >> ch;
  18. bob[i] = ch - '0';
  19. }
  20.  
  21. int a, b, c;
  22. cin >> a >> b >> c;
  23.  
  24. // 统计Bob出拳中0、1、2的数量
  25. int cnt0 = 0, cnt1 = 0, cnt2 = 0;
  26. for (int i = 0; i < n; i++) {
  27. if (bob[i] == 0) cnt0++;
  28. else if (bob[i] == 1) cnt1++;
  29. else cnt2++;
  30. }
  31.  
  32. // 计算最大赢的回合数
  33. int wins = min(b, cnt0) + min(c, cnt1) + min(a, cnt2);
  34.  
  35. cout << wins << endl;
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
5
01201
221
3
222
300
4
0122
112
stdout
5
225
221