QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398694 | #6693. Fast and Fat | xiaole | WA | 172ms | 7088kb | C++23 | 1.2kb | 2024-04-25 16:33:08 | 2024-04-25 16:33:09 |
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.second==r.second) return l.first>l.second;
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(q.size() and 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());
sort(b.begin(),b.end(),cmp);
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
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: 0
Accepted
time: 51ms
memory: 3636kb
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 704877362 960871619 691253609 560579095 136979645 399988835 610497257 576427565 636500913 315900406 370430730 526259135 781258283 631916852 300930080 419999540 431930706 479323438 530080165 391912906 708925499 467782812 457987604 389750718 447390353 696516804 ...
result:
ok 10000 numbers
Test #3:
score: 0
Accepted
time: 71ms
memory: 3660kb
input:
400 908 33362229 606508747 632419478 324326751 257284260 336303174 457246243 986284341 542591728 520499949 519145521 971093641 633038285 374866966 137832222 929747560 626840805 488847915 750542462 328721976 928847956 932651817 479954326 140789806 794986794 212084514 372002273 933710809 173161453 119...
output:
504394967 484359492 469225546 475096879 595868798 497700736 456321846 407898878 591377003 568847769 747288891 512226022 532505353 472511102 511795703 477459477 529231318 472548529 525635770 487622149 510138466 527879972 504505269 498990235 475265402 514165957 449627768 450001628 349076692 507182026 ...
result:
ok 400 numbers
Test #4:
score: 0
Accepted
time: 147ms
memory: 4260kb
input:
10 20711 764663709 192212865 55777289 890465487 406536728 278177638 204765968 477730025 379283253 654167175 41026104 774138002 875860206 465532238 934199361 38168843 545038187 933648246 99831648 715642411 984100235 592340109 870539197 676140250 2503522 500646009 813801461 79167382 531368117 16295473...
output:
499001302 509703433 508081053 500768234 505503494 508790115 506879049 472330839 499777658 493607522
result:
ok 10 numbers
Test #5:
score: 0
Accepted
time: 145ms
memory: 4380kb
input:
5 28172 644161572 775630724 644996423 77402453 959618325 764663709 192212865 55777289 890465487 406536728 278177638 204765968 477730025 379283253 654167175 41026104 774138002 875860206 465532238 934199361 38168843 545038187 933648246 99831648 715642411 984100235 592340109 870539197 676140250 2503522...
output:
500467154 499019830 502230846 506222919 497700052
result:
ok 5 number(s): "500467154 499019830 502230846 506222919 497700052"
Test #6:
score: 0
Accepted
time: 172ms
memory: 7088kb
input:
1 100000 288393588 839718077 938561398 470676893 644161572 775630724 644996423 77402453 959618325 764663709 192212865 55777289 890465487 406536728 278177638 204765968 477730025 379283253 654167175 41026104 774138002 875860206 465532238 934199361 38168843 545038187 933648246 99831648 715642411 984100...
output:
501283249
result:
ok 1 number(s): "501283249"
Test #7:
score: -100
Wrong Answer
time: 23ms
memory: 3644kb
input:
10000 4 2 23 46 91 37 9 28 91 2 52 47 40 35 6 2 23 27 3 26 67 33 43 36 32 35 71 3 74 47 40 26 5 35 29 8 16 88 78 16 72 45 68 31 74 59 35 48 10 88 9 46 43 85 28 19 77 62 29 21 28 95 6 84 98 65 36 90 5 29 86 65 2 20 36 9 31 5 52 71 95 26 28 87 48 48 58 24 60 42 92 90 81 2 58 94 19 63 4 24 66 11 82 9 7...
output:
28 52 33 40 45 58 19 47 45 55 30 41 53 61 6 34 11 52 73 48 40 58 57 28 65 46 41 49 53 45 50 51 53 61 62 55 72 65 56 51 4 47 19 31 39 84 66 58 58 85 50 37 45 35 37 54 62 56 82 40 61 13 42 40 32 70 51 77 44 38 86 35 48 21 86 64 50 44 62 62 35 40 49 66 27 12 47 54 70 66 44 58 70 47 70 28 80 58 57 68 61...
result:
wrong answer 5692nd numbers differ - expected: '32', found: '33'