Problem - E - Codeforces
题意:
思路:
样例:
这种分类讨论的题,主要是去看答案的最终来源是哪几种情况,这几种情况得不重不漏
Code:
#include <bits/stdc++.h>
#define int long long
using i64 = long long;
constexpr int N = 2e5 + 10;
constexpr int mod = 998244353;
int n;
int a[N];
void solve() {
std::cin >> n;
for (int i = 1; i <= n; i ++) {
std::cin >> a[i];
}
int ans = 1e9;
for (int i = 2; i <= n; i ++) {
int u = a[i - 1], v = a[i];
if (u > v) std::swap(u, v);
if (v > 2 * u) {
ans = std::min(ans, (v + 2 - 1) / 2);
}else {
ans = std::min(ans, (u + v + 3 - 1) / 3);
}
}
for (int i = 1; i <= n - 2; i ++) {
int u = a[i];
int v = a[i + 2];
if (u > v) std::swap(u, v);
if (u % 2 == 1 && v % 2 == 1) {
ans = std::min(ans, u / 2 + v / 2 + 1);
}
}
std::sort(a + 1, a + 1 + n);
ans = std::min(ans, (a[1] + 1) / 2 + (a[2] + 1) / 2);
std::cout << ans << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
}