fork(1) download
  1. #include "solution.hpp"
  2. using namespace std;
  3.  
  4. const int N=1e5+20;
  5.  
  6. int n,a[N];
  7. long long dp[N];
  8.  
  9. class Solution {
  10. public:
  11. int solve(vector<int>& nums, int k) {
  12. sort(nums.begin(),nums.end());
  13. if(nums.empty()) return 0;
  14. n=nums.size();
  15. for(int i=1;i<=n;i++)
  16. {
  17. a[i]=nums[i-1];
  18. dp[i]=dp[i-1]+a[i];
  19. }
  20.  
  21. int ans=1,val=a[1];
  22. for(int i=1;i<=n;i++)
  23. {
  24. int lo=i,hi=n,idx=-1;
  25. while(lo<=hi)
  26. {
  27. int mid=(lo+hi)/2;
  28. int mx=a[mid];
  29.  
  30. long long moves=1ll*mx*(mid-i+1)-(dp[mid]-dp[i-1]);
  31. if(moves<=k) idx=mid,lo=mid+1;
  32. else hi=mid-1;
  33. }
  34. if(ans<idx-i+1)
  35. {
  36. ans=idx-i+1;
  37. val=a[idx];
  38. }
  39. }
  40. return val;
  41. }
  42. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: fatal error: solution.hpp: No such file or directory
 #include "solution.hpp"
          ^~~~~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty