原題下載
答案:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5+5;
ll n, k, a[MAXN];
ll ct(double x) {
ll tot = 0;
for (int i = 0; i < n; ++i)
// Using the quadratic formula to solve a[i]/(c(c+1)) >= x
tot += ll((sqrt(1 + 4*a[i]/x)-1)/2);
return tot;
}
int main() {
cin >> n >> k;
k -= n;
for (int i = 0; i < n; ++i)
cin >> a[i];
double lo = 0, hi = 1e18;
for (int i = 0; i < 200; ++i) {
double mid = (lo+hi)/2;
if (ct(mid) >= k)
lo = mid;
else
hi = mid;
}
double ans = 0;
ll tot = 0;
for (int i = 0; i < n; ++i) {
ll x = ll((sqrt(1 + 4*a[i]/lo)-1)/2);
ans += 1.0*a[i]/(x+1);
tot += x;
}
cout << (ll)round(ans - (k-tot)*lo) << endl;
}
以上就是關(guān)于【USACO 2017 January Contest, Platinum Problem 2. Building a Tall Barn】的解答,如需了解學(xué)校/賽事/課程動(dòng)態(tài),可至翰林教育官網(wǎng)獲取更多信息。
往期文章閱讀推薦:
AI奧賽2026國(guó)家隊(duì)名單公布!?新賽季翰林助力直通IOAI全球總決賽!
NOAI人工智能奧賽 2026-2027 活動(dòng)章程出爐:新規(guī)則必看!

? 2026. All Rights Reserved. 滬ICP備2023009024號(hào)-1