0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

C - Water the Trees

https://codeforces.com/contest/1661/submission/153204750
This commit is contained in:
Baoshuo Ren 2022-04-09 23:59:11 +08:00
parent 3c1c434cf0
commit 31e63f59ca
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

52
Codeforces/1661/C/C.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <iostream>
#include <limits>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 3e5 + 5;
int t, n;
long long max, sum, x, a[N], b[N], ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> t;
while (t--) {
ans = std::numeric_limits<long long>::max();
max = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
max = std::max(max, a[i]);
}
for (int _ = 1; _ <= 2; _++, max++) {
sum = x = 0;
for (int i = 1; i <= n; i++) {
b[i] = max - a[i];
}
for (int i = 1; i <= n; i++) {
sum += b[i] / 2 * 2;
x += b[i] % 2;
}
if (x * 2 > sum) {
ans = std::min(ans, x * 2 - 1);
} else {
sum -= x * 2;
ans = std::min(ans, x * 2 + sum / 3 * 2 + sum % 3);
}
}
cout << ans << endl;
}
return 0;
}