QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398659 | #6693. Fast and Fat | xiaole | WA | 43ms | 3576kb | C++23 | 1.2kb | 2024-04-25 16:18:14 | 2024-04-25 16:18:15 |
Judging History
answer
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 1e5+9;const ll MOD = 1e9 + 7;
vector<PLL> a,b;ll n;
bool cmp(PLL l,PLL r){
if(l.first==r.first) return l.second<r.second;
else return l.first>r.first;
}
bool cmp1(PLL l,PLL r){
return l.second>r.second;
}
bool check(ll x){
priority_queue<ll> q;
for (ll i = 0; i < n; i++)
{
if(a[i].first>=x) q.push(a[i].first-x+a[i].second);
}
for (ll i = 0; i< n ; i++)
{
if(b[i].first<x){
if(b[i].second<=q.top()) q.pop();
else return false;
}
}
return true;
}
void solve(){
cin>>n;ll ma=MIN,mi=MAX;
for (ll i = 0; i < n; i++)
{
ll o,p;cin>>o>>p;
ma=max(ma,o);
mi=min(mi,o);
a.push_back({o,p});
b.push_back({o,p});
}
sort(a.begin(),a.end(),cmp);
sort(b.begin(),b.end(),cmp1);
ll l=mi,r=ma;ll ans=0;
while(l<=r){
ll mid=(l+r)/2;
if(check(mid)) {
l=mid+1;ans=mid;
}else r=mid-1;
}
a.clear();
b.clear();
cout<<ans<<"\n";
}
int main(){
ios;ll _=1;cin>>_;
while (_--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
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: 43ms
memory: 3576kb
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 470297536 280572174 715034188 960871619 852497327 562160123 136979645 516531284 610497257 576427565 636500913 315900406 370430730 711095784 781258283 631916852 355137761 565869556 812952251 532872190 657739840 391912906 720993110 467782812 745319288 389750718 798382479 696516804 ...
result:
wrong answer 5th numbers differ - expected: '704877362', found: '715034188'