fork download
  1. #include <bits/stdc++.h>
  2. #include <climits>
  3.  
  4. using namespace std;
  5.  
  6. constexpr int maxk = 101 + 5;
  7.  
  8. inline bool IsNoInRange(int n, int k) {
  9. return n >= 1 && n <= k;
  10. }
  11.  
  12. vector<int> Solve() {
  13. int n, m, k;
  14. cin >> n >> m >> k;
  15. vector<int> seq(n);
  16. for (int& si : seq) {
  17. cin >> si;
  18. si = (si % m) + 1;
  19. }
  20. for (int si : seq) {
  21. cout << si << " ";
  22. }
  23. cout << '\n';
  24.  
  25. int mark[maxk] = {};
  26. int ptr = 0, cnt = 0;
  27. int len = INT_MAX, a = -1, b = -1;
  28.  
  29. for (int i = 0; i < n; ++i) {
  30. if (IsNoInRange(seq[i], k)) {
  31. if (mark[seq[i]] == 0) {
  32. ++cnt;
  33. }
  34. mark[seq[i]]++;
  35. }
  36. while (cnt == k && ptr < i) {
  37. bool flag = false;
  38. if (!IsNoInRange(seq[ptr], k)) {
  39. flag = true;
  40. } else if (mark[seq[ptr]] > 1) {
  41. flag = true;
  42. mark[seq[ptr]]--;
  43. }
  44. if (!flag) break;
  45. ++ptr;
  46. }
  47. if (cnt == k) {
  48. int cur_len = i - ptr + 1;
  49. if (cur_len < len) {
  50. len = cur_len;
  51. a = ptr + 1;
  52. b = i + 1;
  53. } else if (cur_len == len && ptr + 1 < a) {
  54. a = ptr + 1;
  55. b = i + 1;
  56. }
  57. }
  58. }
  59.  
  60. return {len, a, b};
  61. }
  62.  
  63. int main() {
  64. ios_base::sync_with_stdio(0);
  65. cin.tie(0);
  66.  
  67. auto ans = Solve();
  68. cout << (ans[0] == INT_MAX ? "Rango no encontrado"
  69. : to_string(ans[1]) + " " + to_string(ans[2])) << '\n';
  70.  
  71. return 0;
  72. }
  73.  
Success #stdin #stdout 0.01s 5280KB
stdin
5 3 2
1 2 3 4 5
stdout
2 3 1 2 3 
3 4