fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void solveTestCase () {
  7. int Y, P;
  8. cin >> Y >> P;
  9. vector <int> years(P);
  10.  
  11. for(int i=0; i< P; i++) {
  12. cin >> years[i];
  13. }
  14. int maxPopes = 0;
  15. int startYear = 0, endYear = 0;
  16.  
  17. for (int i = 0; i < P; ++i) {
  18. int j = i;
  19. while (j < P && years[j] < years[i] + Y) {
  20. ++j;
  21. }
  22. int count = j - i;
  23. if (count > maxPopes) {
  24. maxPopes = count;
  25. startYear = years[i];
  26. endYear = years[j - 1];
  27. }
  28. }
  29.  
  30. cout << maxPopes << " " << startYear << " " << endYear << "\n";
  31. }
  32.  
  33. int main() {
  34. solveTestCase();
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
20
1
2
3
6
8
12
13
13
15
16
17
18
19
20
20
21
25
26
30
31
stdout
6 16 20