text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
const double pi = 3.14159265358979323846;
using namespace std;
long long fastexp(long long a, long long b) {
long long ans = 1;
long long temp = a;
while (b > 0) {
if (b & 1) ans *= (temp);
temp *= temp;
b >>= 1;
}
return ans;
}
long long GCD(long long a, long long b) {
if (a == 0) return b;
return GCD(b % a, a);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long sum = 0;
long long M = -1;
for (long long i = 0; i < n; i++) {
long long t;
cin >> t;
M = max(M, t);
sum += t;
}
long long temp = ceil(sum / ((n - 1) * 1.0));
cout << max(M, temp);
return 0;
}
|
#include <bits/stdc++.h>
int take() {
int n;
scanf("%d", &n);
return n;
}
double ttake() {
double n;
scanf("%lf", &n);
return n;
}
long long takes() {
long long n;
scanf("%lld", &n);
return n;
}
int cas;
using namespace std;
bool approximatelyEqual(float a, float b, float epsilon) {
return fabs(a - b) <= ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool essentiallyEqual(float a, float b, float epsilon) {
return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool definitelyGreaterThan(float a, float b, float epsilon) {
return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool definitelyLessThan(float a, float b, float epsilon) {
return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
int main() {
int mx = 0, n = take(), v;
long long tot = 0;
for (int i = 1; i <= n; i++) v = take(), mx = max(v, mx), tot += v;
long long l = mx, h = 1000000000000000000;
while (l <= h) {
long long m = l + (h - l) / 2;
long long p = ceil(tot / ((n - 1) * 1.00));
if (m >= p && m >= mx) {
h = m - 1;
} else
l = m + 1;
}
cout << h + 1 << "\n";
{ return 0; };
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100005], maxx;
bool isOK(long long x) {
long long cnt = 0;
for (int i = 1; i <= n; i++) {
if (x > a[i]) cnt += x - a[i];
if (cnt >= x) return 1;
}
if (cnt >= x)
return 1;
else
return 0;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
maxx = max(maxx, a[i]);
}
long long l = maxx, r = (long long)1e16;
while (r - l > 3) {
long long mid = (l + r) / 2;
if (isOK(mid))
r = mid;
else
l = mid;
}
for (long long i = l; i <= r; i++) {
if (isOK(i)) {
cout << i;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, f[100005], max = 0, sum = 0, l;
scanf("%lld", &a);
for (int i = 0; i < a; i++) scanf("%lld", &f[i]);
sort(f, f + a);
for (int i = a - 2; i >= 0; i--) {
f[i] -= sum;
if (f[i] <= 0) {
printf("%lld", f[a - 1]);
return 0;
}
sum += f[i + 1] - f[i];
}
if (sum != f[a - 1]) {
while (f[0] >= a) {
f[0] = f[0] - a + 1;
sum += a;
}
if (f[0] > 0) sum += f[0] + 1;
}
printf("%lld", sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double h = 1e-6;
const int MAX_ = 200005;
inline long long int mul(long long int a, long long int b) {
return (a * 1ll * b) % 1000000007;
}
inline long long int sub(long long int a, long long int b) {
long long int c = a - b;
if (c < 0) c += 1000000007;
return c;
}
inline long long int add(long long int a, long long int b) {
long long int c = a + b;
if (c > 1000000007) c -= 1000000007;
return c;
}
long long int sqr(long long int x) { return x * x; }
int main() {
int n;
cin >> n;
long long sum = 0;
long long xl[100010];
for (int i = 0; i < n; i++) {
cin >> xl[i];
sum += xl[i];
}
sort(xl, xl + n);
long long x = sum / (n - 1);
if (sum % (n - 1)) {
cout << max(xl[n - 1], x + 1);
} else {
cout << max(xl[n - 1], x);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x, all, n, s, i, j = -1;
all = 0;
cin >> n;
for (i = 1; i <= n; i++) cin >> s, all += s, j = (j < s) ? s : j;
n--;
if (all / n < j)
cout << j;
else if (all % n)
cout << (all / n) + 1;
else
cout << all / n;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[100001];
long int n;
bool possible(long long int x) {
int j = 0;
long long int rounds = 0;
while (j < n) {
rounds += (x - a[j]);
if (rounds >= x) {
return true;
}
j++;
}
return false;
}
int main() {
cin >> n;
long long int mx = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > mx) mx = a[i];
}
long long int l = mx;
long long int r = 1000000000000000000;
long long int mid;
long long int ans = r;
while (l <= r) {
mid = (l + r) / 2;
if (possible(mid)) {
if (mid < ans) ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int Num;
char CH[20];
const int inf = 0x3f3f3f3f;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void P(int x) {
Num = 0;
if (!x) {
putchar('0');
puts("");
return;
}
while (x > 0) CH[++Num] = x % 10, x /= 10;
while (Num) putchar(CH[Num--] + 48);
puts("");
}
long long a[200001];
long long sum = 0;
long long mx = 0;
int main() {
int n = read();
for (int i = 1; i <= n; i++) a[i] = read(), sum += a[i], mx = max(a[i], mx);
n = n - 1;
long long ans;
ans = sum / n;
if (sum % n != 0) ans++;
cout << max(mx, ans) << endl;
}
|
#include <bits/stdc++.h>
int main() {
long n;
scanf("%ld", &n);
long long total(0), minRounds(0);
for (long p = 0; p < n; p++) {
long temp;
scanf("%ld", &temp);
total += temp;
if (temp > minRounds) {
minRounds = temp;
}
}
long long rounds = total / (n - 1);
if (total % (n - 1) > 0) {
++rounds;
}
if (rounds < minRounds) {
rounds = minRounds;
}
printf("%lld\n", rounds);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
long long v[100005], n;
bool isPossible(long long play) {
long long sum = 0;
for (int i = 0; i < n; ++i) {
sum += v[i];
if (sum >= n - 1) {
sum -= (n - 1);
--play;
}
if (play < 0) return 0;
}
if (sum > 0) {
play -= ceil((double)sum / (n - 1));
}
return (play >= 0);
}
long long binarySearch(long long l, long long r) {
long long ans = -1;
while (l <= r) {
long long mid = (l + r) >> 1LL;
if (isPossible(mid)) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
cin >> n;
for (int i = 0; i < n; ++i) cin >> v[i];
sort(v, v + n);
cout << binarySearch(v[n - 1], 1e18) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
long long sum;
long long mx = 0;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
;
cin >> n;
for (int i = 0; i < n; i++) {
long long t;
cin >> t;
sum += t;
mx = max(mx, t);
}
long long ans = (sum) / (n - 1) + (sum % (n - 1) != 0);
cout << max(ans, mx) << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100001];
bool check(long long t) {
long long i, j;
long long x = t, sum = 0;
for (i = 0; i < n; i++) {
sum += (t - a[i]);
if (sum >= t) return true;
}
return false;
}
void solve() {
sort(a, a + n);
long long mid, l = a[n - 1], r = a[n - 1] + a[0];
while (r - l > 1) {
mid = l + (r - l) / 2;
if (check(mid))
r = mid;
else
l = mid;
}
if (check(l))
cout << l << endl;
else
cout << r << endl;
}
int main(void) {
int i;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) scanf("%I64d", &a[i]);
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
long long k = 0;
for (int i = 0; i < n; i++) k = max(k, a[i]);
long long t = 0;
for (int i = 0; i < n; i++) t += k - a[i];
if (t >= k) {
cout << k << endl;
return 0;
} else {
double p = ((double)(k - t)) / ((double)(n - 1));
k += ceil(p);
cout << k << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie();
int n;
cin >> n;
int a[n], i;
long long sum = 0;
for (i = 0; i < n; ++i) {
cin >> a[i];
sum += a[i];
}
int maxE = *max_element(a, a + n);
long long ans = sum / (n - 1);
if (ans * (n - 1) < sum) ans++;
cout << max(ans, (long long)maxE);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[100005];
int main() {
long long int n, i, s = 0, maxa = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > maxa) maxa = a[i];
s += a[i];
}
n--;
cout << max(maxa, (s + n - 1) / n) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int n;
bool ok(long long x) {
long long s = 0;
for (int i = 0; i < n; ++i) {
s += x - a[i];
}
for (int i = 0; i < n; ++i) {
if (a[i] > s - (x - a[i])) return false;
}
return true;
}
int main() {
int maxx = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
maxx = max(maxx, a[i]);
}
long long end = (long long)(maxx) * (long long)(n);
long long begin = maxx;
while (begin < end) {
long long mid = begin + (end - begin) / 2;
if (ok(mid))
end = mid;
else
begin = mid + 1;
}
cout << begin << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[100009], ans;
long long n;
bool chk(long long md) {
long long sum = 0;
for (int i = 1; i <= n; i++) {
if (a[i] > md) return false;
sum += md - a[i];
}
return sum >= md;
}
int main() {
cin >> n;
long long l, r, mid;
long long ssum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ssum += a[i];
}
l = 1;
r = ssum;
while (l <= r) {
mid = (l + r) / 2;
if (chk(mid)) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long int linf = 0x3f3f3f3f3f3f3f3f;
const long double pi = acos(-1.0);
const int mod = 1e9 + 7;
const int maxn = 100050;
long long int v[maxn];
int n;
bool testa(long long int p) {
long long int precisa = p;
for (int i = 0; i < n; i++) {
long long int livres = p - v[i];
if (livres < 0) return false;
precisa -= min(precisa, livres);
}
return precisa <= 0;
}
long long int bb(long long int e, long long int d) {
if (e >= d) return e;
long long int m = (e + d) / 2;
if (testa(m))
return bb(e, m);
else
return bb(m + 1, d);
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) cin >> v[i];
cout << bb(0, linf) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a, ma = 0, cnt = 0;
scanf("%I64d", &n);
for (int i = 0; i < n; i++) {
scanf("%I64d", &a);
if (a > ma) ma = a;
cnt += a;
}
a = ceil((double)cnt / (n - 1)), a = max(a, ma);
printf("%I64d", a);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a;
long long max_last = -1, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
sum += a;
max_last = max(a, max_last);
}
long long ans = sum / (n - 1);
if (sum % (n - 1) != 0) ans++;
if (max_last > ans) ans += (max_last - ans);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
int ans = a[n - 1];
int s = 0;
for (int i = 0; i < n; i++) {
s += ans - a[i];
if (s >= ans) break;
}
while (s < ans) {
int t = (ans - s) / n + (bool)((ans - s) % n);
ans += t;
s += t * n;
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long sum = 0;
long long n, nn[(int)1e5 + 5];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> nn[i];
sum += nn[i];
}
sum = (sum + (n - 2)) / (n - 1);
sort(nn, nn + n);
cout << max(nn[n - 1], sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
constexpr string_view gtype() {
string_view s = __PRETTY_FUNCTION__;
return string_view(s.data() + 45, s.find(';', 45) - 45);
}
const int MAXN = 1e6;
int arr[MAXN];
int main() {
long long n;
cin >> n;
long long lead = 0;
for (int i = 0; i < n; i++) cin >> arr[i];
long long mx = *max_element(arr, arr + n);
for (int i = 0; i < n; ++i) {
lead += (mx - arr[i]);
};
;
long long ans = 0;
if (lead >= mx)
ans = mx;
else {
ans = mx + (mx - lead + n - 2) / (n - 1);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[100010];
int main() {
long long n, maxi = 0LL;
cin >> n;
long long sum = 0;
for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i], maxi = max(maxi, a[i]);
long long x;
x = (sum % (n - 1) == 0 ? sum / (n - 1) : (sum / (n - 1)) + 1);
cout << (x >= maxi ? x : maxi);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getmin(T *a, const T &b) {
if (b < *a) {
*a = b;
return true;
}
return false;
}
template <class T>
inline bool getmax(T *a, const T &b) {
if (b > *a) {
*a = b;
return true;
}
return false;
}
template <class T>
inline void read(T *a) {
char c;
while (isspace(c = getchar())) {
}
bool flag = 0;
if (c == '-')
flag = 1, *a = 0;
else
*a = c - 48;
while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
if (flag) *a = -*a;
}
const int mo = 1000000007;
template <class T>
T pow(T a, T b, int c = mo) {
T res = 1;
for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c)
if (b & i) res = 1LL * res * a % c;
return res;
}
const int N = 100100;
int a[N], n;
bool check(long long x) {
long long res = 0;
for (int i = (1); i <= (n); ++i) {
if (a[i] > x) return 0;
res += x - a[i];
}
return res >= x;
}
int main() {
cin >> n;
for (int i = (1); i <= (n); ++i) read(a + i);
long long l = 1, r = 1e12, res;
while (l <= r) {
long long mid = (l + r) >> 1;
if (check(mid))
r = mid - 1, res = mid;
else
l = mid + 1;
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 100;
long long arr[maxn];
bool test(long long mid, int n) {
long long x = 0;
for (int i = 0; i < n; i++) x += mid - arr[i];
if (x >= mid) return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long long sum = 0;
long long ans = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum = max(sum, arr[i]);
}
long long l = sum, r = 1e10;
while (l != r) {
long long mid = (l + r) / 2;
if (test(mid, n))
r = mid;
else
l = mid + 1;
}
cout << r << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long *a;
int n;
bool valid(long long m) {
long long spvsr = 0LL;
for (int i = 0; i < n; i++) {
spvsr += m - a[i];
}
return (spvsr >= m) ? true : false;
}
int main() {
cin >> n;
long long minGames = LLONG_MIN;
a = new long long[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
minGames = max(minGames, a[i]);
}
long long l = minGames, r = 2 * minGames, ans = 0LL;
while (l <= r) {
long long m = l + (r - l) / 2;
if (valid(m)) {
r = m - 1;
ans = m;
} else
l = m + 1;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, k, l, sum = 0, n;
cin >> n;
long long arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
long long x = (sum / (n - 1));
if (sum > x * (n - 1)) x++;
long long y = *max_element(arr, arr + n);
if (x < y)
cout << y;
else
cout << x;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int a[n + 1], maxi;
a[n] = 0;
maxi = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
maxi = max(a[i], maxi);
a[n] += a[i];
}
double sum = a[n], k = n - 1;
long long int r;
r = ceil(sum / k);
cout << max(r, maxi) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> v(n);
long long sum = 0;
for (int i = 0; i < n; ++i) {
cin >> v[i];
sum += v[i];
}
long long ans = sum / (n - 1);
if (sum % (n - 1)) ans++;
if (ans < *max_element(v.begin(), v.end()))
ans = *max_element(v.begin(), v.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, a[N];
int main() {
cin >> n;
for (int i = 0; i < (n); ++i) cin >> a[i];
long long low = 1, high = 1e18, mid;
for (int i = 0; i < (n); ++i) low = max<long long>(low, a[i]);
while (low < high) {
mid = (low + high) / 2;
bool ok = 0;
long long tmp = a[0];
for (int i = 0; i < (n); ++i)
if (i) {
if (tmp <= mid - a[i]) {
ok = 1;
break;
}
tmp -= mid - a[i];
}
if (ok)
high = mid;
else
low = mid + 1;
}
cout << low << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int a[n];
long long int sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
long long int x = ceil((sum * 1.0) / (n - 1));
long long int z = *max_element(a, a + n);
cout << max(x, z);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int i;
long long l, r, mid, n, ma, a[200000], s;
bool ok() {
s = 0;
for (i = 1; i <= n; i++) {
s += mid - a[i];
if (s >= mid) return true;
}
return false;
}
int main() {
cin >> n;
ma = 0;
for (i = 1; i <= n; i++) {
cin >> a[i];
ma = max(a[i], ma);
}
l = ma;
r = 1 << 30;
for (i = 1; i <= 20; i++) r = r * 2;
while (l < r) {
mid = (l + r) >> 1;
if (ok())
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 100005;
const ll mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, ans = 0, a[N];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
for (int i = 2; i <= n; i++) {
a[i] -= ans;
ll res = 0;
res = (a[i] - a[i - 1]) * (i - 1);
res = min(res, a[i]);
ans += res;
a[i] -= res;
}
ans +=
((a[n] % (n - 1) != 0) ? (a[n] % (n - 1) + 1) : (0)) + a[n] / (n - 1) * n;
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long sumA = 0, n;
cin >> n;
long long ma = 0;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
sumA += x;
ma = max(ma, x);
}
long long A = ceil(sumA / (long double)(n - 1));
A = max(A, ma);
cout << A;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long a[n];
long long maxr = 0, sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] > maxr) maxr = a[i];
}
long long ans = sum / (n - 1);
if (sum % (n - 1) != 0) ans += 1;
ans = max(ans, maxr);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
if (a > b) return a;
return b;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
long long s = 0;
long long mx = 0;
for (int i = 1; i <= n; i++) {
int e;
cin >> e;
s += e;
mx = max(mx, e);
}
cout << max(mx, (long long)(ceil((s * 1.0) / (n - 1)))) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int MAX(long long int a, long long int b) {
if (a > b) return a;
return b;
}
int main() {
long long int n;
long long int p = 0;
cin >> n;
int max = 0;
for (long long int i = 1; i <= n; i++) {
long long int now;
cin >> now;
if (now > max) max = now;
p += now;
}
double it = 1.0 * p / (n - 1);
if (it == p / (n - 1))
printf("%I64d\n", MAX(p / (n - 1), max));
else
printf("%I64d\n", MAX(p / (n - 1) + 1, max));
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[100001];
long long n;
bool check(long long rounds) {
long long ved = 0;
for (int i = 0; i < n; i++) ved += (rounds - a[i]);
return rounds <= ved;
}
long long binary(long long l, long long r) {
if ((l + 1) == r) {
return r;
} else {
long long m = (l + r) / 2;
if (check(m))
return binary(l, m);
else
return binary(m, r);
}
}
int main() {
cin >> n >> a[0];
long long maxval = a[0], sum = a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
maxval = max(a[i], maxval);
sum += a[i];
}
cout << binary(maxval - 1, sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long all = 0;
long long ans = 0;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
ans = max(ans, x);
all += x;
}
n = n - 1;
long long round = 0;
while (true) {
if (all > 0) {
round++;
all -= n;
} else
break;
}
cout << max(round, ans) << '\n';
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, i, m, a, sum, s;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
if (a > m) m = a;
sum += a;
}
sum -= m;
s = m * (n - 1);
s -= sum;
if (s >= m) {
cout << m;
return 0;
}
s = m - s;
s = (s - 1) / ((n - 1)) + 1;
cout << m + s;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x;
cin >> n;
long long sum = 0, maxi = -LONG_LONG_MAX;
for (int i = 0; i < n; i++) {
cin >> x;
sum += x;
maxi = max(x, maxi);
}
long long ans = !(sum % (n - 1)) ? sum / (n - 1) : (sum / (n - 1)) + 1;
cout << max(maxi, ans) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long sum = 0, maxi = 0;
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
maxi = max(maxi, a);
sum += a;
}
long long ans = (sum % (n - 1) == 0) ? sum / (n - 1) : sum / (n - 1) + 1;
cout << max(maxi, ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main(void) {
long long n;
cin >> n;
long long arr[n + 2];
long long sum = 0;
long long div1 = n - 1;
long long maxval = 0;
for (long long i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
maxval = max(maxval, arr[i]);
}
long long ans = 0;
if (sum % div1 == 0) {
ans = sum / div1;
} else {
ans = sum / div1 + 1;
}
cout << max(maxval, ans) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int n, a[N];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int Max = -1;
for (int i = 0; i < n; i++) Max = max(Max, a[i]);
long long int cans = 0;
for (int i = 0; i < n; i++) cans += Max - a[i];
cerr << "CANS: " << cans << endl;
if (Max - cans > 0) {
int stmt = Max - cans;
cans += (stmt / (n - 1)) * n;
stmt %= n - 1;
if (stmt != 0) cans += stmt + 1;
cout << cans;
} else
cout << Max;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long a[maxn];
int n;
bool ok(long long x) {
long long res = 0;
for (int i = 0; i < n; ++i) res += x - a[i];
return res >= x;
}
long long solve() {
long long left = *max_element(a, a + n);
long long right = 2e9;
while (left <= right) {
long long mid = (left + right) >> 1;
if (ok(mid))
right = mid - 1;
else
left = mid + 1;
}
return right + 1;
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
std::cout << solve() << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i = -1;
long long s = 0;
int ma = 0;
scanf("%d", &n);
while (++i < n) {
int a;
scanf("%d", &a);
s += a;
if (ma < a) ma = a;
}
--n;
long long m = s / n;
if (s % n) ++m;
if (m < ma) m = ma;
printf("%I64d\n", m);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100100];
long long x;
int ma;
long long sum;
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
ma = max(ma, a[i]);
sum += 1ll * a[i];
}
int l = ma - 1, r = 2000000005;
int mid;
while (l + 1 < r) {
mid = (1ll * l + r) / 2;
x = 1ll * mid * n - sum;
if (x >= mid)
r = mid;
else
l = mid;
}
cout << r;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, ave, maxa = 0;
long long a[100005];
long long sum = 0;
int main() {
scanf("%I64d", &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
sum += a[i];
if (a[i] > maxa) maxa = a[i];
}
if (sum % (n - 1))
ave = sum / (n - 1) + 1;
else
ave = sum / (n - 1);
printf("%I64d", max(maxa, ave));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long answer = 0;
long long input = 0;
long long minput = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> input;
answer += input;
minput = max(minput, input);
}
answer += (n - 2);
answer /= (n - 1);
if (answer > minput)
cout << answer << '\n';
else
cout << minput << '\n';
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
cout << "[";
for (int i = 0; i < v.size(); i++) {
if (i) cout << ", ";
cout << v[i];
}
return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
const long long MAXN = 1e5 + 7;
void check() {
long long n, mx = 0;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i], mx = max(mx, a[i]);
long long ans = mx, sm = 1e18;
while (1) {
sm = 0;
for (long long i = 0; i < n; i++) sm += (ans - a[i]);
if (sm >= ans) break;
ans++;
}
cout << ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
for (int i = 1; i <= t; i++) {
check();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long powmod(long long x, long long y) {
long long t;
for (t = 1; y; y >>= 1, x = x * x % mod)
if (y & 1) t = t * x % mod;
return t;
}
unsigned long long gcd(long long x, long long y) {
return y ? gcd(y, x % y) : x;
}
long long lcm(long long x, long long y) { return x * (y / gcd(x, y)); }
void smask(int pos, int &i) { i = i ^ (1 << pos); }
void clmask(int pos, int &i) { i = i & ~(1 << pos); }
bool chmask(int pos, int i) { return i & (1 << pos); }
double cordist(pair<double, double> a, pair<double, double> b) {
return sqrt(((a.first - b.first) * (a.first - b.first)) +
((a.second - b.second) * (a.second - b.second)));
}
long long n, m, q, r;
void solve() {
cin >> n;
long long sum = 0;
long long maxs = 0;
for (int i = 0; i < n; i++) {
cin >> m;
maxs = max(maxs, m);
sum += m;
}
sum = ceil((double)sum / (n - 1));
cout << max(maxs, sum) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int k = 1;
while (k--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
template <typename T, typename U>
inline void swap(T &a, U &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
inline void swap(int &a, int &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
inline void swap(long long &a, long long &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (b > a) a = b;
}
template <typename T, typename U>
inline void smin(T &a, U b) {
if (b < a) a = b;
}
inline int gcd(int a, int b) {
if (a < b) swap(a, b);
while (b > 0) {
a %= b;
swap(a, b);
}
return a;
}
long long nchose(int a, int b) {
long long ans = 1;
smax(a, b - a);
int p = 2;
for (int i = (b - a + 1); i <= (b); i++) {
ans *= (long long)i;
while (p <= a && ans % p == 0) ans /= p++;
}
return ans;
}
using namespace std;
static int MOD = 1000000007;
int n, a[100001], ans, ex;
int main() {
cin >> n;
for (int i = (0); i < (n); i++) cin >> a[i];
sort(a, a + n);
ex = a[n - 1];
ans = ex;
for (int i = (n - 1); i >= (0); i--) {
ans -= ex - a[i];
if (ans <= 0) {
cout << ex;
return 0;
}
}
cout << ex + (ans + n - 2) / (n - 1);
}
|
#include <bits/stdc++.h>
int n, i;
long long w, sum, max;
bool kt;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%I64d", &w);
sum += w;
if (max < w) max = w;
}
n--;
if (sum % n != 0) kt = true;
sum = sum / n;
if (kt) sum++;
if (sum < max) sum = max;
printf("%I64d", sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, a, maxi = 0;
double sum = 0, x;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
maxi = max(maxi, a);
sum += (double)a;
}
x = ceil(sum / (n - 1));
long long y = x;
y = max(maxi, y);
cout << y << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct abc {
long long int fri, mon;
};
bool compare(abc x1, abc x2) { return (x1.mon < x2.mon); }
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);
}
long long int min(long long int a, long long int b) {
if (a < b) return a;
return b;
}
bool isprime(long long int n) {
if (n == 1) return false;
for (long long int i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
const long long int N = 2e5 + 3, A = 1e6 + 3;
int32_t main() {
long long int n;
cin >> n;
long long int a[n], ans = 0, sum = 0, max = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > max) max = a[i];
sum += a[i];
}
long long int count = sum / (n - 1);
if (sum % (n - 1) != 0) count += 1;
if (count < max) count = max;
cout << count;
}
|
#include <bits/stdc++.h>
using namespace std;
int64_t A[100006], n;
bool isPossible(int64_t r) {
int64_t sum = 0;
for (int64_t i = 0; i < n; i++) {
sum += (r - A[i]);
}
if (sum >= r) {
return true;
}
return false;
}
int main() {
int64_t high = 0, low = 0;
cin >> n;
for (int64_t i = 0; i < n; i++) {
cin >> A[i];
high += A[i];
low = max(low, A[i]);
}
int64_t ans = high;
while (low <= high) {
int64_t mid = (low + high) / 2;
if (isPossible(mid)) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long m, s, ans, a, n;
int main() {
scanf("%lld", &n);
for (long long i = 1; i <= n; i++) {
scanf("%lld", &a);
m = max(m, a), s += a;
}
ans = (s + n - 2ll) / (n - 1ll);
if (ans < m) ans = m;
printf("%lld", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int INF = INT_MAX;
const int MAX_N = 1e5 + 10;
template <typename T>
inline T sqr(T a) {
return a * a;
};
int N;
long long sum = 0, ans = 0, lmax = 0, A[MAX_N];
int main(int argc, char const *argv[]) {
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> A[i];
sum += A[i];
lmax = max(A[i], lmax);
}
ans = sum / (N - 1) + (sum % (N - 1) ? 1 : 0);
cout << max(ans, lmax) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long x, s = 0, ma = -1;
for (long long i = 0; i < (n); i++) {
cin >> x;
s += x;
if (x > ma) ma = x;
}
long long ans;
if (s % (n - 1) == 0)
ans = s / (n - 1);
else
ans = s / (n - 1) + 1;
cout << max(ma, ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, n, m, sum, an;
const long long N = 500010;
long long a[N];
bool cheak(long long mid) {
for (long long i = 1; i <= n; i++)
if (a[i] > mid) return false;
long long s = 0;
for (long long i = 1; i <= n; i++) s += mid - a[i];
if (s >= mid) return true;
return false;
}
int main() {
scanf("%I64d", &n);
for (long long i = 1; i <= n; i++) scanf("%I64d", &a[i]), m = max(a[i], m);
long long l = 0;
long long r = n * m;
while (l < r - 1) {
long long mid = (l + r) / 2;
if (cheak(mid))
r = mid;
else
l = mid;
}
printf("%I64d\n", r);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long double n, a[100004], mx, sum;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i], mx = max(mx, a[i]), sum += a[i];
cout << (long long int)max(ceil(sum / (n - 1)), mx) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[111111], n;
int main() {
cin >> n;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
sum = sum / (n - 1) + (sum % (n - 1) != 0);
sort(a, a + n);
if (sum < a[n - 1]) {
cout << a[n - 1];
cin >> n;
return 0;
}
cout << sum << "\n";
cin >> n;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec[i];
}
long long sum = 0;
long long mn = 0;
for (int i = 0; i < n; i++) {
sum += vec[i];
mn = max(mn, vec[i]);
}
sum = (sum + n - 2) / (n - 1);
mn = max(mn, sum);
cout << mn << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long> maf(n + 1);
maf[0] = -1;
for (int i = 1; i <= n; i++) {
cin >> maf[i];
}
sort(maf.begin(), maf.end());
long long vv = 0;
long long max = maf[n];
for (int i = 1; i < n; i++) {
vv += (max - maf[i]);
if (vv >= max) break;
}
if (vv < max) {
double more = ceil((max - vv) * 1.0 / (n - 1));
max += more;
}
cout << max << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, x, Max, sum;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
cin >> n;
n--;
for (int i = 0; i <= n; ++i) cin >> x, sum += x, Max = max(Max, x);
cout << max((sum / n) + bool(sum % n), Max) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6, mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, sum = 0;
cin >> n;
long long x;
long long nm = 0;
for (long long i = 0; i < n; i++) {
cin >> x;
nm = max(nm, x);
sum += x;
}
if (sum % (n - 1) == 0)
sum = sum / (n - 1);
else
sum = sum / (n - 1) + 1;
cout << max(sum, nm) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long sum = 0, maxv = INT_MIN, cnt;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
sum += val;
if (val > maxv) maxv = val;
}
cnt = maxv * (n - 2);
sum = sum - maxv - cnt;
if (sum <= 0)
cout << maxv << "\n";
else {
if ((sum % (n - 1) != 0)) {
cout << (long long)(maxv + sum / (n - 1) + 1) << endl;
} else {
cout << (long long)(maxv + sum / (n - 1)) << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100000 + 5];
bool f(int m, long long x) {
long long aux = 0;
for (int i = 1; i < n; ++i) {
if (a[i] - m > a[0]) return false;
aux += max(0, a[i] - m);
}
if (aux <= x) return true;
return false;
}
int bs(long long x) {
int lo = 0, hi = a[n - 1];
while (lo < hi) {
int m = lo + (hi - lo) / 2;
if (f(m, x))
hi = m;
else
lo = m + 1;
}
return lo;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", a + i);
sort(a, a + n);
long long x = (long long)a[0] * (n - 2);
int ans = bs(x);
printf("%d\n", ans + a[0]);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int i, j, k, temp;
long long int sum = 0, maxm;
vector<int> a;
cin >> n;
for (i = 0; i < n; i++) {
cin >> temp;
a.push_back(temp);
sum += temp;
}
sort(a.begin(), a.end());
maxm = a[n - 1];
long long int b = sum % (n - 1);
sum /= (n - 1);
if (b) sum++;
cout << max(maxm, sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long maxm = INT_MIN;
long long sum = 0;
for (long long i = 0; i < n; ++i) {
long long x;
cin >> x;
sum += x;
maxm = max(maxm, x);
}
long long ans = sum / (n - 1) + (sum % (n - 1) == 0 ? 0 : 1);
if (ans >= maxm) {
cout << ans << '\n';
} else
cout << maxm << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(static_cast<unsigned>(time(0)));
long long t;
t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a[100000];
long long int n;
bool check(long long int rn) {
long long int flag = 1;
long long int sp = 0;
for (long long int i = 0; i < n; i++) {
sp += (rn - a[i]);
}
if (sp >= rn) return true;
return false;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (long long int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long int low = a[n - 1], high = 1e14 + 10;
long long int ans;
while (low <= high) {
long long int mid = (low + high) / 2;
if (check(mid)) {
ans = mid;
high = mid - 1;
} else
low = mid + 1;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
const long long MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-10);
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int real(), int imag()) { return real() > imag(); }
int dcp(double A, double B) { return fabs(A - B) <= EPS ? 0 : A < B ? -1 : 1; }
bool prime(int x) {
if (x == 1) {
return false;
}
if (x == 2) {
return true;
}
if (x % 2 == 0) {
return false;
}
for (int i = 3; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
unsigned long long ncr(long long x, long long y) {
if (y == 0 || x == 0) {
return 1;
}
if (y == 1) {
return x;
}
return (x * ncr(x - 1, y - 1)) / y;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long sum = 0;
long long mx = 0;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
sum += x;
mx = max(mx, x);
}
cout << max((sum + n - 2) / (n - 1), mx);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, sum = 0;
scanf("%I64d", &n);
long long int a, res, ma = 0;
for (int i = 0; i < n; i++) {
scanf("%I64d", &a);
sum += a;
if (a > ma) ma = a;
}
res = ceil((double)sum / (n - 1));
res = max(ma, res);
printf("%I64d", res);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int chkpower2(int x) { return (x && !(x & x - 1)); }
void solve() {
long long int n;
cin >> n;
long long int a[n], sum = 0;
for (int i1 = 0; i1 < n; i1++) {
cin >> a[i1];
sum += a[i1];
}
sort(a, a + n);
if (sum % (n - 1)) {
sum = sum / (n - 1) + 1;
} else {
sum = sum / (n - 1);
}
cout << max(a[n - 1], sum);
return;
}
int main() {
int t;
t = 1;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a[100005] = {0}, i;
long long int sum = 0, ans, x;
scanf("%I64d", &n);
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
sum += a[i];
x = (x > a[i] ? x : a[i]);
}
ans = sum / (n - 1);
if (sum % (n - 1) != 0) ans++;
printf("%I64d\n", (ans > x ? ans : x));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[n];
long long int i, ans, z, m;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
ans = a[n - 1];
long long int l = a[n - 1], r = 100000000000000000;
long long int mid;
long long int answer = 100000000000000000;
while (l <= r) {
mid = (l + r) / 2;
ans = mid;
for (i = 0; i < n; i++) {
z = a[i];
m = mid - z;
ans = ans - m;
if (ans <= 0) break;
}
if (ans <= 0) {
answer = min(answer, mid);
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << answer << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;
int main() {
int n;
cin >> n;
vector<long long> A(n);
for (int i = (int)(0); i < (int)(n); i++) cin >> A[i];
sort((A).begin(), (A).end());
long long lb = 0;
long long ub = 1LL << 40;
while (ub - lb > 1) {
long long mb = (ub + lb) / 2;
bool ok = true;
if (mb < A.back()) ok = false;
long long sum = 0;
for (int i = (int)(0); i < (int)(n); i++) sum += mb - A[i];
if (ok && sum >= mb) {
ub = mb;
} else {
lb = mb;
}
}
cout << ub << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<int> a(n, 0);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
long long s = 0, k;
for (int i = 0; i < n; i++) {
s += a[i];
}
if (s % (n - 1) == 0) {
k = s / (n - 1);
} else {
k = (s / (n - 1)) + 1;
}
long long max = 0;
for (int i = 0; i < n; i++) {
if (a[i] > max) {
max = a[i];
}
}
if (k < max) {
cout << max;
} else {
cout << k;
}
return 0;
}
|
#include <bits/stdc++.h>
const int dx[4] = {0, 0, 0, 0};
using namespace std;
long long a[100010];
int main(int argc, char** argv) {
long long n, max, sum, ans;
while (scanf("%"
"l"
"l"
"d",
&n) != EOF) {
max = 0;
for (int i = 0; i < n; i++) {
scanf(
"%"
"l"
"l"
"d",
&a[i]);
if (max < a[i]) max = a[i];
}
sum = 0;
for (int i = 0; i < n; i++) {
sum += (max - a[i]);
}
if (sum >= max) {
printf(
"%"
"l"
"l"
"d"
"\n",
max);
} else {
ans = max - sum;
if (ans % (n - 1) == 0)
ans = max + ans / (n - 1);
else
ans = max + ans / (n - 1) + 1;
printf(
"%"
"l"
"l"
"d"
"\n",
ans);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n;
cin >> n;
vector<long long int> a(n);
long long int maxi, mini = 0, sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
mini = max(mini, a[i]);
}
maxi = sum + 1;
long long int med = (maxi + mini) / 2LL;
while (maxi - mini > 1) {
if (med * n - sum > med) {
maxi = med;
} else {
mini = med;
}
med = (maxi + mini) / 2LL;
}
if (mini * n - sum >= mini)
std::cout << mini << std::endl;
else
std::cout << maxi << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool check_prime(long long n) {
long long flag = 0;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
flag = 1;
break;
}
}
if (n == 1)
return false;
else if (flag == 0 || n == 2 || n == 3) {
return true;
} else {
return false;
}
}
long long BE(long long x, long long n, long long m) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = result * x % m;
x = x * x % m;
n = n / 2;
}
return result;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
long long l = 1;
long long r = (1e18 + 5) / 10000;
long long m = 0;
long long flag = 0;
long long ans;
while (l <= r) {
m = l + (r - l) / 2;
ans = m;
long long k = 0;
flag = 1;
for (long long i = 0; i < n; i++) {
if (m < a[i]) {
flag = 0;
break;
}
k += max(0LL, m - a[i]);
}
if (m == 2) {
}
if (k < m) flag = 0;
if (flag == 0) {
l = m + 1;
} else {
r = m - 1;
}
}
cout << l << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long N, big = 0, gap = 0;
cin >> N;
long long A[N];
for (long long i = 0; i < N; i++) {
cin >> A[i];
big = max(big, A[i]);
}
for (long long i = 0; i < N; i++) gap += big - A[i];
if (gap >= big)
cout << big << endl;
else
cout << big + (long long)ceil((double)(big - gap) / (N - 1)) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF_MAX = 0x7FFFFFFF;
const int INF_MIN = -(1 << 30);
const double eps = 1e-10;
const double pi = acos(-1.0);
int toInt(string s) {
istringstream sin(s);
int t;
sin >> t;
return t;
}
template <class T>
string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T>
inline T gcd(T a, T b) {
if (a < 0) return gcd(-a, b);
if (b < 0) return gcd(a, -b);
return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
if (a < 0) return lcm(-a, b);
if (b < 0) return lcm(a, -b);
return a * (b / gcd(a, b));
}
template <class T>
inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q) {
while (!Q.empty()) Q.pop();
}
inline int random(int l, int r) { return rand() % (r - l + 1) + l; }
int dir_4[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int dir_8[8][2] = {{0, 1}, {-1, 1}, {-1, 0}, {-1, -1},
{0, -1}, {1, -1}, {1, 0}, {1, 1}};
int main() {
long long n;
long long sum = 0;
long long maxx = -1;
cin >> n;
for (long long i = 0; i < n; i++) {
long long tmp;
cin >> tmp;
sum += tmp;
maxx = max(maxx, tmp);
}
cout << max((sum + n - 2) / (n - 1), maxx) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int mat[100][100];
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
long long n, a, s, m;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a, m = max(a, m), s += a;
cout << max(m, (s - 1) / (n - 1) + 1);
return 0;
}
|
#include <bits/stdc++.h>
const int maxn = 100005;
long long a[maxn], n;
bool check(long long x1) {
long long sum = 0;
bool flag = true;
for (int i = 1; i <= n; ++i) {
if (x1 >= a[i])
sum += x1 - a[i];
else {
flag = false;
break;
}
}
if (!flag) return false;
if (sum >= x1)
return true;
else
return false;
}
int main() {
scanf("%I64d", &n);
for (int i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
long long l = 1ll, r = 2000000005ll, mid, ans;
while (l <= r) {
mid = (l + r) >> 1;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
printf("%I64d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, a, mx = 0, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
mx = max(mx, a);
sum += a;
}
cout << max(mx, (long long)ceil(1.0 * sum / (n - 1))) << '\n';
return 0;
}
|
#include <bits/stdc++.h>
int main() {
long long i, r, n, sum = 0, a[100005], max = -1;
scanf("%I64d", &n);
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
sum += a[i];
if (a[i] > max) {
max = a[i];
}
}
r = ceil(sum / (n - 1.0));
if (r < max) {
r = max;
}
printf("%I64d\n", r);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, i, a[120000], sm, b, ans;
int main() {
while (scanf("%I64d", &n) == 1) {
for (i = 0; i < n; i++) scanf("%I64d", &a[i]);
sort(a, a + n);
sm = 0;
for (i = 1; i < n - 1; i++) sm += (a[n - 1] - a[i]);
if (sm >= a[0])
printf("%I64d\n", a[n - 1]);
else {
ans = a[0];
b = a[0] - sm;
ans += b / (n - 1);
if (b % (n - 1) == 0)
ans += a[n - 1] - a[0];
else
ans += (a[n - 1] - a[0]) + 1;
printf("%I64d\n", ans);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long r, n;
cin >> n;
long long mx = 0, sum = 0;
for (int i = 0; i < n; i++) cin >> r, sum += r, mx = max(mx, r);
cout << max(mx, (long long)ceil((double)sum / (double)(n - 1)));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
int a[n + 2];
long long int i, j;
long long int sum = 0;
long long int ans = INT_MIN;
for (i = 1; i <= n; i++) {
cin >> a[i];
sum = sum + a[i];
long long int c = a[i];
ans = max(ans, c);
}
double m = n - 1;
double z = sum / m;
long long int q = ceil(z);
cout << max(ans, q);
}
|
#include <bits/stdc++.h>
using namespace std;
int mat[100][100];
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
long long n, a, s, m;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a, m = max(a, m), s += a;
long long avg = s / (n - 1);
if (s % (n - 1)) avg++;
cout << max(m, avg);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
vector<long long> a(n);
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
cout << max(*max_element((a).begin(), (a).end()), (sum - 1) / (n - 1) + 1)
<< "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, a, sum, mx;
int main() {
cin >> n;
for (auto i = 0; i < n; i++) {
cin >> a;
mx = max(a, mx);
sum += a;
}
sum--, n--;
cout << max(mx, (sum) / (n) + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[n], k, sum = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
sort(a, a + n);
k = n - 1;
if (sum % k == 0) {
k = sum / k;
cout << max(k, a[n - 1]) << endl;
} else {
k = sum / k;
k++;
cout << max(k, a[n - 1]) << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, ma;
long long int s;
int x[111111];
int main() {
scanf("%d", &n);
ma = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &x[i]);
ma = max(ma, x[i]);
}
s = 0LL;
for (int i = 0; i < n; i++) s += ma - x[i];
while (s < ma) {
s += n;
ma++;
}
printf("%d\n", ma);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
T my_pow(T n, T p) {
if (p == 0) return 1;
T x = my_pow(n, p / 2);
x = (x * x);
if (p & 1) x = (x * n);
return x;
}
template <class T>
T big_mod(T n, T p, T m) {
if (p == 0) return (T)1;
T x = big_mod(n, p / 2, m);
x = (x * x) % m;
if (p & 1) x = (x * n) % m;
return x;
}
template <class T>
inline T Mod(T n, T m) {
return (n % m + m) % m;
}
template <class T>
T extract(string s, T ret) {
stringstream ss(s);
ss >> ret;
return ret;
}
template <class T>
string itos(T n) {
ostringstream ost;
ost << n;
ost.flush();
return ost.str();
}
long long stoi(string s) {
long long r = 0;
istringstream sin(s);
sin >> r;
return r;
}
double toDouble(string s) {
double r = 0;
istringstream sin(s);
sin >> r;
return r;
}
long long ar[2000005], ar1[200005];
long long a = 0, b = 0, c = 0, r = 0, rr = 0, res = 0, n, m;
string s, ss;
long long fun(long long val) {
r = 0;
for (__typeof(n) i = 0; i < (n); i++) {
if (val < ar[i]) return false;
r += (val - ar[i]);
}
if (r >= val)
return true;
else
return false;
}
int main() {
cin >> n;
for (__typeof(n) i = 0; i < (n); i++) {
cin >> ar[i];
}
long long lo = 0, hi = 10000000000ll;
while (hi - lo > 1) {
long long mid = (lo + hi) >> 1;
if (fun(mid))
hi = mid;
else
lo = mid;
}
cout << hi;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long n, a[N], sum, mx, ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] > mx) mx = a[i];
}
cout << max(mx, (long long)ceil((double)sum / (double)(n - 1)));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
while (cin >> n) {
long long sum = 0;
long long mx = 0;
long long val;
for (int i = 0; i < n; i++) {
cin >> val;
sum += val;
mx = max(mx, val);
}
while ((mx * n) - sum < mx) {
mx++;
}
cout << mx << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long powe(long long x, long long y) {
x = x % mod, y = y % (mod - 1);
long long ans = 1;
while (y > 0) {
if (y & 1) {
ans = (1ll * x * ans) % mod;
}
y >>= 1;
x = (1ll * x * x) % mod;
}
return ans;
}
void fun() {}
const long long N = 1e6 + 7;
long long sortby(tuple<long long, long long, long long> v,
tuple<long long, long long, long long> v1) {
return get<0>(v) > get<0>(v1);
}
bool isPrime(long long n) {
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
fun();
long long tt = 1;
while (tt--) {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long ans = a[n - 1];
long long sum = 0;
for (long long i = 0; i < n; i++) sum += a[i];
sum = ceil((double)sum / (double)(n - 1));
cout << max(ans, sum);
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.