fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int Y, P, popes[100001];
  5.  
  6. int binser_upper(int cari) {
  7. // upper bound
  8. int L = 0, R = P-1, M = (L+R+1)/2;
  9. while(L < R) {
  10. if(popes[M] <= cari)
  11. L = M;
  12. else // popes[M] > cari
  13. R = M-1;
  14. M = (L+R+1)/2;
  15. }
  16. return L+1;
  17. }
  18.  
  19. int main() {
  20. while(cin >> Y >> P) {
  21. for(int i = 0; i < P; i++)
  22. cin >> popes[i];
  23. int max_ans = -1, max_year = -1;
  24. for(int i = 0; i < P; i++) {
  25. int cari = Y+popes[i]-1;
  26. int ans = binser_upper(cari)-i;
  27. // cout << i << " " << popes[i] << " " << cari << " " << ans << endl;
  28. if(ans > max_ans) {
  29. max_ans = ans;
  30. max_year = i;
  31. }
  32. }
  33. cout << max_ans << " " << popes[max_year] << " " << Y+popes[max_year]-1 << endl;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5276KB
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