题意:
思路:
将 [2,n] 范围内的塔楼进行排序,动态维护第一座塔楼的高度。每次可以将 高度差⌊高度差/2⌋ 的高度转移给一号塔楼,先转移矮的一定更优秀,不浪费原则。
参考代码:
void solve() {
int n;
std::cin >> n;
std::vector<int> a(n);
cin(a);
ll ans = 1LL * a[0];
std::sort(a.begin() + 1, a.end());
for (int i = 1; i < n; i++) {
if (a[i] > ans) {
int temp = a[i] - ans;
temp = (temp + 1) / 2;
ans += temp;
}
}
std::cout << ans << "\n";
}
因篇幅问题不能全部显示,请点此查看更多更全内容