原题下载
答案:
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> pii;
vector<pii> V;
int N;
int main(void)
{
ifstream fin ("pairup.in");
ofstream fout ("pairup.out");
fin >> N;
for (int i=0; i<N; i++) {
int x, y;
fin >> x >> y;
V.push_back(pii(y,x));
}
sort(V.begin(), V.end());
int M = 0, i=0, j=N-1;
while (i <= j) {
int x = min(V[i].second, V[j].second);
if (i==j) x /= 2;
M = max(M, V[i].first + V[j].first);
V[i].second -= x;
V[j].second -= x;
if (V[i].second == 0) i++;
if (V[j].second == 0) j--;
}
fout << M << "\n";
return 0;
}
以上就是关于【USACO 2017 US Open Contest, Silver Problem 1. Paired Up】的解答,如需了解学校/赛事/课程动态,可至翰林教育官网获取更多信息。
往期文章阅读推荐:
2026 NOAI国际AI奥赛中国站即将开考!赛事地址&日程已出!
2027 USAAIO美国AI奥赛启动报名!MIT/谷歌/Jane Street集体站台!

© 2026. All Rights Reserved. 沪ICP备2023009024号-1