fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main(){
  6. int periodo, n;
  7. while(cin >> periodo >> n) {
  8. vector<int> a(n);
  9. for(int i = 0; i < n; i++)
  10. cin >> a[i];
  11. int mx = 0, low = -1, high = -1;
  12. for(int i = 0; i < n; i++) {
  13. int inicio = a[i];
  14. int fin = a[i] + periodo - 1; //2006
  15. int aa = i, bb = n;
  16. while(bb - aa > 1) {
  17. int c = (aa + bb) / 2;
  18. if(a[c] <= fin)
  19. aa = c;
  20. else
  21. bb = c;
  22. }
  23. int cont = aa - i + 1;
  24. if(cont > mx) {
  25. mx = cont;
  26. low = inicio;
  27. high = a[aa];
  28. }
  29. }
  30. cout << mx << " " << low << " " << high << "\n";
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty