diff --git a/Codeforces/1661/C/C.cpp b/Codeforces/1661/C/C.cpp new file mode 100644 index 00000000..ea178147 --- /dev/null +++ b/Codeforces/1661/C/C.cpp @@ -0,0 +1,52 @@ +#include +#include + +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::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; +}