QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671878 | #6693. Fast and Fat | Schoolbag | TL | 0ms | 3532kb | C++20 | 1.7kb | 2024-10-24 14:50:32 | 2024-10-24 14:50:32 |
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;
};
while(l < r){
ll mid = (l + r) / 2;
if(check(mid)) l = mid;
else r = mid - 1;
}
cout << l << '\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: 3532kb
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
Time Limit Exceeded
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...