main.cc 839 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <algorithm>
  2. #include <cstdio>
  3. #include <map>
  4. using namespace std;
  5. const int N = 100000;
  6. int n, s, type[N];
  7. int main() {
  8. int T;
  9. scanf("%d", &T);
  10. for (int t = 1; t <= T; t++) {
  11. scanf("%d %d", &n, &s);
  12. for (int i = 0; i < n; i++) scanf("%d", &type[i]);
  13. int cnt = 0;
  14. map<int, int> freq;
  15. for (int i = 0; i < n; i++) {
  16. freq.clear();
  17. int cur_cnt = 0;
  18. for (int j = i; j < n; j++) {
  19. if (freq.find(type[i]) == freq.end()) {
  20. freq[type[j]] = 1;
  21. cur_cnt++;
  22. } else {
  23. int f = freq[type[j]];
  24. if (f < s) {
  25. cur_cnt++;
  26. } else if (f == s) {
  27. cur_cnt -= s;
  28. }
  29. freq[type[j]] = f + 1;
  30. }
  31. cnt = max(cnt, cur_cnt);
  32. }
  33. }
  34. printf("Case #%d: %d\n", t, cnt);
  35. }
  36. return 0;
  37. }