fork download
  1. /*
  2.  
  3.   I n u z u k a S h i n o -w-
  4.  
  5. */
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8.  
  9. #define FILE(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
  10. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  11. #define FOR(i, x, n) for (auto i = x; i <= n; ++i)
  12. #define FOD(i, x, n) for (auto i = x; i >= n; --i)
  13. #define REP(i, n) for (auto i = 0; i < n; ++i)
  14. #define ALL(v) (v).begin(), (v).end()
  15.  
  16.  
  17. #define fi first
  18. #define se second
  19. #define ll long long
  20. #define pb push_back
  21. #define vi vector<int>
  22. #define pii pair<int, int>
  23.  
  24.  
  25. const int N = 1e3 + 5;
  26. const int maxn = 1e5 + 5;
  27. const ll MOD = 1e9 + 7;
  28.  
  29.  
  30. int n, k, a[maxn];
  31. int main(){
  32. cin.tie(0) -> sync_with_stdio(0);
  33. FILE("TASK");
  34.  
  35. cin >>n >>k;
  36. FOR(i, 1, n) cin >>a[i];
  37.  
  38. sort(a + 1, a + n + 1);
  39.  
  40. int cnt = 0, x = 0;
  41.  
  42. int l = 1;
  43. ll up = 0;
  44.  
  45. FOR(r, 1, n){
  46. if (r > 1) up += 1LL * (a[r] - a[r - 1]) * (r - l);
  47.  
  48. // cerr <<up <<' ';
  49.  
  50. while (up > k) up -= a[r] - a[l++];
  51.  
  52. int cur = r - l + 1;
  53.  
  54. if (cur > cnt) cnt = cur, x = a[r];
  55. }
  56.  
  57. cout <<cnt <<' ' <<x <<'\n';
  58.  
  59. return 0;
  60. }
Success #stdin #stdout #stderr 0s 5292KB
stdin
5 3 
3 1 2 2 1
stdout
4 2
stderr
0 0 2 2 6