QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378469 | #6693. Fast and Fat | Credit | WA | 1ms | 3516kb | C++17 | 1.2kb | 2024-04-06 13:07:01 | 2024-04-06 13:07:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
void solve()
{
int n;
cin >> n;
vector<pair<ll, ll>>a(n + 1);
ll mx = 0;
for (int i = 1;i <= n;i++) {
cin >> a[i].first >> a[i].second;
mx = max(mx, a[i].first);
}
int l = 1, r = mx;
while (l < r) {
int mid = (r + l) >> 1;
auto check = [&] (int x) -> bool {
vector<ll> v1, v2;
for (int i = 1;i <= n;i++) {
if (a[i].first < x)v2.push_back(a[i].second);
else v1.push_back(a[i].first + a[i].second - x);
}
int p1 = 0;
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
for (auto i : v2) {
while (p1 < v1.size() && v1[p1] < i)p1++;
if (p1 == v1.size())return 1;
p1++;
}
return 0;
};
if (check(mid))r = mid;
else l = mid + 1;
}
cout << r << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3516kb
input:
2 5 10 5 1 102 10 100 7 4 9 50 2 1 100 10 1
output:
9 2
result:
wrong answer 1st numbers differ - expected: '8', found: '9'