fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. using pii = pair<int,int>;
  5. using pll = pair<ll,ll>;
  6. #define FOR(i,a,b) for(ll i = (a);i <= (b);i++)
  7. #define FOD(i,a,b) for(ll i = (a);i >= (b);i--)
  8. #define el '\n'
  9. #define ft first
  10. #define sc second
  11. const ll mang = 1e5 + 5;
  12. const ll MOD = 1e9 + 7;
  13. const ll MAX = 1e18;
  14. const ll MAXMASK = (1 << 18);
  15. ll n,m,d,q,k,k2;
  16. vector<ll> a;
  17. ll prek1[mang],prek2[mang];
  18. ll check(ll m){
  19. ll d = 0;
  20. FOR(i,1,n){
  21. if(a[i] < m) d += m - a[i];
  22. }
  23. return d;
  24. }
  25. ll cnpmin(){
  26. ll l = 1,r = 1e5,ans = -1;
  27. while(l <= r){
  28. ll m = l + r >> 1;
  29. if(check(m) <= k){
  30. l = m + 1;
  31. ans = m;
  32. }
  33. else r = m - 1;
  34. }
  35. return ans + (check(ans) != k);
  36. }
  37. int main(){
  38. cin.tie(0) -> sync_with_stdio(0);
  39. // freopen("LEGO.INP","r",stdin);
  40. // freopen("LEGO.OUT","w",stdout);
  41. cin >> n >> k;
  42. a.resize(n + 1);
  43. ll c = 0;
  44. FOR(i,1,n) cin >> a[i],c = max(c,a[i]);
  45. cout << max(c,cnpmin()) << " ";
  46. cout << c + k;
  47. }
  48.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
100000 0