fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fi first
  5. #define se second
  6. #define MOD 1000000007
  7. #define FOR(i,a,b) for (int i = (a);i <= (b);i++)
  8. #define FOD(i,a,b) for (int i = (b);i >= (a);i--)
  9. #define ALL(x) (x).begin(),(x).end()
  10. #define ii pair<int,int>
  11. #define iii pair<int,pair<int,int>>
  12. //const int MOD = 998244353;
  13. const int MAXN = 3e5 + 7;
  14. ll a[MAXN];
  15. int main(){
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(0); cout.tie(0);
  18. //freopen("cardscore.inp","r",stdin);
  19. //freopen("cardscore.out","w",stdout);
  20. ll n,k;cin >> n >> k;
  21. FOR(i,1,n)cin >> a[i];
  22. sort(a + 1,a + 1 + n);
  23. ll tot = 0;
  24. FOR(i,1,n)tot = tot + a[n] - a[i];
  25. // if (tot <= k)return cout << a[n] + (k - tot) / n,0;
  26. int id = n;tot = (tot - a[n] * n) * -1;
  27. FOD(i,1,a[n] + 10000){
  28. while (id > 0 && a[id] > i){
  29. tot = tot - a[id];
  30. id--;
  31. }
  32. ll w = k - i * id + tot;
  33. FOD(j,id + 1,n){
  34. w = w + (a[j] % i == 0 ? i : a[j] % i) - i;
  35. if (w < 0)break;
  36. }
  37. if (w >= 0)return cout << i,0;
  38. }
  39. return 0^0;
  40. }
Success #stdin #stdout 0.01s 5280KB
stdin
5 12345
1 2 3 4 5
stdout
2472