QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#705152 | #6693. Fast and Fat | tacmon | WA | 75ms | 3756kb | C++14 | 1.1kb | 2024-11-02 22:19:18 | 2024-11-02 22:19:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int N, v[maxn], w[maxn];
vector<int> good;
vector<int> bad;
bool check(int mid) {
good.clear(), bad.clear();
for (int i = 1; i <= N; i++) {
if (v[i] < mid) bad.push_back(w[i]);
if (v[i] > mid) good.push_back(w[i] + v[i] - mid);
}
sort(good.begin(), good.end());
reverse(good.begin(), good.end());
sort(bad.begin(), bad.end());
reverse(bad.begin(), bad.end());
if (bad.size() > good.size()) return false;
int pos = 0;
for (int i = 0; i < (int)bad.size(); i++) {
while (pos + 1 < (int)good.size() && good[pos + 1] >= bad[i]) pos++;
if (pos < i || good[pos] < bad[i]) return false;
}
return true;
}
void solve() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> v[i] >> w[i];
int L = 0, R = 1000000000, res = 0;
while(L <= R) {
int mid = (L + R) >> 1;
if (!check(mid)) R = mid - 1;
else res = mid, L = mid + 1;
}
printf("%d\n", res);
}
int main() {
// freopen("a.in", "r", stdin);
int T = 0;
cin >> T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3756kb
input:
2 5 10 5 1 102 10 100 7 4 9 50 2 1 100 10 1
output:
8 1
result:
ok 2 number(s): "8 1"
Test #2:
score: -100
Wrong Answer
time: 75ms
memory: 3740kb
input:
10000 4 280251502 664541723 375808746 641141991 95134537 898607509 455259328 944978891 2 798417052 547329847 785434740 991778535 6 623628702 857611223 275667427 453747403 292209526 283132767 330752033 988721243 470297536 608192332 477186035 325224271 3 280572174 994054447 306566740 923535026 3781360...
output:
352409014 785434740 470297535 280572173 704877362 960871618 691253608 560579094 136979645 399988835 610497257 576427564 636500913 315900405 370430730 526259135 781258283 631916851 300930080 419999539 431930706 479323438 530080164 391912906 708925498 467782812 457987604 389750718 447390353 696516804 ...
result:
wrong answer 3rd numbers differ - expected: '470297536', found: '470297535'