fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define pb push_back
  5. #define all(a) a.begin(), a.end()
  6. #define rep(i, x, n) for (int i = x; i <= n; ++i)
  7. #define inp(a) freopen(a".inp", "r", stdin), freopen(a".out", "w", stdout)
  8.  
  9. const int N = 2e5 + 5;
  10.  
  11.  
  12. int n, k;
  13. long long a[N], pre[N];
  14.  
  15. int get(int xino){
  16. int l = 0, r = xino;
  17.  
  18. while (r - l > 1){
  19. int m = l + r >> 1;
  20.  
  21. if ((xino - m + 1) * a[xino] - (pre[xino] - pre[m - 1]) <= k) r = m;
  22. else l = m;
  23. }
  24.  
  25. return xino - r + 1;
  26. }
  27. int main(){
  28. cin.tie(0) -> sync_with_stdio(0);
  29. inp("hopqua");
  30.  
  31. cin >>n >>k;
  32.  
  33. rep(i, 1, n) cin >>a[i];
  34.  
  35. sort(a + 1, a + n + 1);
  36. rep(i, 1, n) pre[i] = pre[i - 1] + a[i];
  37.  
  38. int cnt = 0, value = 0;
  39.  
  40. rep(i, 1, n){
  41. int c = get(i);
  42.  
  43. if (c > cnt){
  44. cnt = c; value = a[i];
  45. }
  46. }
  47.  
  48. cout <<cnt <<' ' <<value;
  49.  
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty