fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<int> a;
  25.  
  26. bool isPossible(int n, int k, int mid){
  27. int extra = k;
  28. for(int i=0; i<n; i++){
  29. int x = mid - a[i];
  30. extra -= x;
  31.  
  32. }
  33.  
  34. if(extra <= 0) return true;
  35. return false;
  36.  
  37. }
  38.  
  39. void consistency(int n, int k){
  40.  
  41. int s = 0, e = INF;
  42. for(int i=0; i<n; i++) s = max(s, a[i]);
  43.  
  44. if(k==0){
  45. cout << s << endl;
  46. return;
  47. }
  48.  
  49. while(s<e){
  50. int mid = s + (e-s)/2;
  51. if(isPossible(n, k, mid)){
  52. e = mid;
  53. }
  54. else s = mid+1;
  55. }
  56.  
  57. cout << e << endl;
  58.  
  59. }
  60.  
  61. void solve() {
  62.  
  63. int n, k;
  64. cin>>n >> k;
  65.  
  66. a.resize(n);
  67. for(int i=0; i<n; i++) cin >> a[i];
  68.  
  69. consistency(n, k);
  70.  
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. int32_t main() {
  79. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  80.  
  81. int t = 1;
  82. cin >> t;
  83. while (t--) {
  84. solve();
  85. }
  86.  
  87. return 0;
  88. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
5 25
7 5 1 9 1
3 3
1 2 3
1 3
1
stdout
10
3
4