QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671952 | #6693. Fast and Fat | Schoolbag | WA | 53ms | 3888kb | C++20 | 1.8kb | 2024-10-24 15:07:08 | 2024-10-24 15:07:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vc;
typedef vector<long long> vl;
typedef vector<vector<long long>> vll;
typedef __int128_t int128;
#define rep(x, y, z) for(int x = (y); x <= (z); x++)
#define per(x, y ,z) for(int x = (y); x >= (z); x--)
#define yes cout << "YES\n"
#define no cout << "NO\n"
//#define int long long
//const int N = 1e5 + 5;
//const int mod = 1e9 + 7;
const ll inf = 1e10;
void solve(){
int n; cin >> n;
vector<pll> a(n + 1, {-1, -1}), b(n + 1, {-1, -1});
ll l = inf, r = -inf;
rep(i, 1, n){
cin >> a[i].first >> a[i].second; // v, w
b[i] = a[i];
l = min(l, a[i].first);
r = max(r, a[i].first);
}
sort(a.begin() + 1, a.end(), [&](pll x, pll y){
return x.first + x.second > y.first + y.second;
});
sort(b.begin() + 1, b.end(), [&](pll x, pll y){
return x.second > y.second;
});
auto check = [&](ll tar) -> bool{
vl p, q;
rep(i, 1, n){
if(a[i].first >= tar){
p.push_back(a[i].first + a[i].second - tar);
}
if(b[i].first < tar){
q.push_back(b[i].second);
}
}
if(p.size() < q.size()) return 0;
rep(i, 0, (int)q.size() - 1){
if(p[i] < q[i]) return 0;
}
return 1;
};
ll ans = l;
while(l < r){ // 找符合条件的最大值
ll mid = (l + r) / 2; // ac
// ll mid = (l + r) / 2; tle
if(check(mid)) l = mid + 1, ans = mid;
else r = mid - 1;
}
cout << ans << '\n';
}
signed main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int __ = 1; cin >> __;
while(__--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 53ms
memory: 3888kb
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 560579095 136979645 399988834 610497257 576427564 636500913 315900405 370430730 526259134 781258283 631916852 300930080 419999539 431930706 479323437 530080164 391912905 708925498 467782812 457987603 389750718 447390352 696516804 ...
result:
wrong answer 3rd numbers differ - expected: '470297536', found: '470297535'