Submission #3918375


Source Code Expand

Copy
#include <bits/stdc++.h>
#define mid ((l+r)>>1)
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n; lnt a[55], s, tot;
bool chk(lnt x) {
	lnt cnt = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] > x) cnt += (a[i]-x)/(n+1);
	return cnt <= s-n*n;
}
lnt bi_solve(lnt l, lnt r) {
	lnt ret = r;
	while (l <= r)
		if (!chk(mid)) l = mid+1;
		else ret = mid, r = mid-1;
	return ret;
}
void solve() {
	if (s >= n*n) {
		lnt mx = 0;
		for (int i = 1; i <= n; i++)
			a[i] += s-n*n, mx = max(mx, a[i]);
		lnt x = bi_solve(0, mx);
		for (int i = 1; i <= n; i++) if (a[i] > x)
			tot += (a[i]-x)/(n+1), a[i] -= (a[i]-x)/(n+1)*(n+1);
		for (int p = 1; tot < s-n*n; p = 1, tot++) {
			for (int i = 2; i <= n; i++)
				if (a[i] > a[p]) p = i;
			a[p] -= n+1;
		}
	}
	for (int p = 1; ; p = 1, tot++) {
		for (int i = 2; i <= n; i++)
			if (a[i] > a[p]) p = i;
		if (a[p] < n) break;
		for (int i = 1; i <= n; i++)
			if (i == p) a[i] -= n; else a[i]++;
	}
}
int main() {
	read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]), s += a[i];
	return solve(), printf("%lld\n", tot), 0;
}

Submission Info

Submission Time
Task E - Decrease (Judge ver.)
User Azrael_Death
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1308 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 5
AC × 35
Set Name Test Cases
Sample example0, example1, example2, example3, example4
All example0, example1, example2, example3, example4, maxrand0, maxrand1, maxrand2, maxrand3, maxrand4, maxrand5, maxrand6, maxrand7, maxrand8, maxrand9, rand0, rand1, rand2, rand3, rand4, rand5, rand6, rand7, rand8, rand9, small0, small1, small2, small3, small4, small5, small6, small7, small8, small9
Case Name Status Exec Time Memory
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
example3 AC 1 ms 256 KB
example4 AC 1 ms 256 KB
maxrand0 AC 1 ms 256 KB
maxrand1 AC 1 ms 256 KB
maxrand2 AC 1 ms 256 KB
maxrand3 AC 1 ms 256 KB
maxrand4 AC 1 ms 256 KB
maxrand5 AC 1 ms 256 KB
maxrand6 AC 1 ms 256 KB
maxrand7 AC 1 ms 256 KB
maxrand8 AC 1 ms 256 KB
maxrand9 AC 1 ms 256 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB
rand3 AC 1 ms 256 KB
rand4 AC 1 ms 256 KB
rand5 AC 1 ms 256 KB
rand6 AC 1 ms 256 KB
rand7 AC 1 ms 256 KB
rand8 AC 1 ms 256 KB
rand9 AC 1 ms 256 KB
small0 AC 1 ms 256 KB
small1 AC 1 ms 256 KB
small2 AC 1 ms 256 KB
small3 AC 1 ms 256 KB
small4 AC 1 ms 256 KB
small5 AC 1 ms 256 KB
small6 AC 1 ms 256 KB
small7 AC 1 ms 256 KB
small8 AC 1 ms 256 KB
small9 AC 1 ms 256 KB