| 比赛 |
ry分享赛 |
评测结果 |
AATTTTTTTT |
| 题目名称 |
服务 |
最终得分 |
20 |
| 用户昵称 |
LikableP |
运行时间 |
8.892 s |
| 代码语言 |
C++ |
内存使用 |
1.54 MiB |
| 提交时间 |
2026-03-19 20:15:07 |
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <numeric>
typedef long long ll;
const int MAXN = 2.5e4 + 10;
int n;
int a[MAXN], b[MAXN];
int order[MAXN];
ll ans = 0x7fffffffffffffff;
int main() {
#ifdef LOCAL
freopen("!input.in", "r", stdin);
freopen("!output.out", "w", stdout);
#else
freopen("service.in", "r", stdin);
freopen("service.out", "w", stdout);
#endif
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &a[i], &b[i]);
}
std::iota(order + 1, order + n + 1, 1);
do {
ll now = 0, waiting = 0;
for (int i = 1; i <= n; ++i) {
if ((now += a[order[i]]) >= ans) break;
if (waiting <= now) {
waiting = now + b[order[i]];
} else if (waiting > now) {
waiting += b[order[i]];
}
}
ans = std::min(ans, std::max(now, waiting));
} while (std::next_permutation(order + 1, order + n + 1));
printf("%lld\n", ans);
return 0;
}