原題下載
答案:
#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;
}
以上就是關于【USACO 2017 January Contest, Platinum Problem 2. Building a Tall Barn】的解答,如需了解學校/賽事/課程動態,可至翰林教育官網獲取更多信息。
往期文章閱讀推薦:
2027 USAAIO人工智能奧賽報名進行中!Round 1新規出爐,2月開賽如何備考?
外灘大會見證AI爆發!緊跟智能時代,從USACO計算機奧賽起步!

? 2026. All Rights Reserved. 滬ICP備2023009024號-1