fork download
  1. /// Angry Cows (Gold)
  2. /// Author: Qwerty
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. int n;
  6. int a[10000];
  7. int expIndex(int hay[], int start, bool left){
  8. int last = start;
  9. int r = 1;
  10. int dir;
  11. if (left)
  12. dir = -1;
  13. else
  14. dir = 1;
  15. if (left){
  16. while (last > 0 && last - 1 < n - 1){
  17. int next = last;
  18. while ((next + dir >= 0 && next + dir < n) && abs(hay[next + dir] - hay[last]) <= r){
  19. next += dir;
  20. }
  21. if (next == last)
  22. break;
  23. last = next;
  24. r++;
  25. }
  26. }
  27. else {
  28. while (last < n - 1){
  29. int next = last;
  30. while ((next + dir >= 0 && next + dir < n) && abs(hay[next + dir] - hay[last]) <= r){
  31. next += dir;
  32. }
  33. if (next == last)
  34. break;
  35. last = next;
  36. r++;
  37. }
  38. }
  39. return last;
  40. }
  41. int main(){
  42. //freopen("angry.in","r",stdin);
  43. //freopen("angry.out","w",stdout);
  44. int ans=0;
  45. cin>>n;
  46. for (int i=0;i<n;i++){
  47. cin>>a[i];
  48. }
  49. sort(a,a+n);
  50. for (int i = 0; i < n; i++){
  51. int left=expIndex(a,i,true);
  52. int right=expIndex(a,i,false);
  53. int explode=right-left+1;
  54. if (explode>ans)
  55. ans=explode;
  56. }
  57. cout<<ans;
  58. }
  59.  
Success #stdin #stdout 0.01s 5284KB
stdin
5
8
10
3
11
1
stdout
3