fork download
  1. #include <iterator>
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9.  
  10. map<ll, ll> :: iterator it, pr;
  11. map<ll, ll> m;
  12.  
  13. ll n, k, i, a[100100], mx = 0;
  14. int main() {
  15. freopen("repair.in", "r", stdin);
  16. freopen("repair.out", "w", stdout);
  17.  
  18. scanf("%I64d%I64d", &n, &k);
  19. for(i = 0; i < n; i ++){
  20. scanf("%I64d", a + i);
  21. m[a[i]] ++; mx = max(mx, a[i]);
  22. }
  23. for(it = m.begin(); it != m.end(); it ++){
  24. if(it == m.begin()){
  25. pr = m.begin();
  26. continue;
  27. }
  28. else{
  29. ll dif = it -> first - pr -> first;
  30. ll kol = pr -> second;
  31. ll req = dif * kol;
  32. ll can = min(k, req);
  33. ll lev = can / kol;
  34. ll ost = can % kol;
  35.  
  36. if(k > can){
  37. m[it -> first] += kol;
  38. m[pr -> first] = 0;
  39. k -= can; pr = it;
  40. }
  41. else{
  42. printf("%I64d", lev + pr -> first);
  43. return 0;
  44. }
  45. }
  46. }
  47. printf("%I64d", mx + k / n);
  48. return 0;
  49. }
  50.  
Runtime error #stdin #stdout 0s 4120KB
stdin
Standard input is empty
stdout
Standard output is empty