ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#198035 | #3456. 跑步比赛 | JuRuoError_YBW | 100 | 1354ms | 4404kb | C++ | 990b | 2023-11-19 13:24:33 | 2023-11-19 16:04:41 |
answer
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define int long long
const int MAXN=2e5+5;
struct node{
int v,w;
}a[MAXN];
bool pd(int w,int n){
std::priority_queue<int> p,q;
for(int i=1;i<=n;i++){
if(w>a[i].v)p.push(a[i].w);
else q.push(a[i].v-w+a[i].w);
}
while(1){
if(p.empty()||q.empty()){
return p.empty();
}
if(p.top()>q.top())return 0;
p.pop();
q.pop();
}
}
void solve(){
int n;
std::cin>>n;
int maxx=0;
for(int i=1;i<=n;i++){
std::cin>>a[i].v>>a[i].w;
maxx=std::max(maxx,a[i].v);
}
int l=1,r=maxx,ans=0;
while(l<=r){
int mid=(l+r)/2;
if(pd(mid,n)){
//std::cout<<mid<<'\n';
ans=mid;
l=mid+1;
}
else r=mid-1;
}
std::cout<<ans<<'\n';
}
signed main(){
int t;
std::cin>>t;
while(t--)solve();
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
1 10 266993 706803678 802362985 892644371 953855359 196462821 817301757 409460796 773943961 48876395...
output:
555904242
result:
ok single line: '555904242'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
1 10 46 15 50 98 93 77 31 43 84 90 6 24 14 37 73 29 43 9 4 8
output:
46
result:
ok single line: '46'
Test #3:
score: 10
Accepted
time: 2ms
memory: 1260kb
input:
20 300 538289667 450937378 534888897 527066716 80798460 335568208 947853348 207336428 510842953 1625...
output:
505659071 550791327 628691185 463559292 127705784 468121697 411937181 435008942 421342654 510493557 ...
result:
ok 20 lines
Test #4:
score: 10
Accepted
time: 0ms
memory: 1252kb
input:
20 83 8 14 31 91 97 72 23 73 68 70 51 78 2 19 10 38 11 16 19 64 97 47 43 65 28 88 63 50 49 23 28 37 ...
output:
44 58 46 64 57 64 43 66 46 52 57 61 46 53 73 39 53 54 42 43
result:
ok 20 lines
Test #5:
score: 10
Accepted
time: 0ms
memory: 1292kb
input:
1 1000 93 758062633 88 981601925 22 28054989 72 269036456 41 161626551 15 521363191 3 244982120 50 2...
output:
20
result:
ok single line: '20'
Test #6:
score: 10
Accepted
time: 5ms
memory: 1292kb
input:
1 1000 223444244 49 154763608 49 914282513 57 594690778 49 46129939 20 592083152 16 459436308 39 650...
output:
534391186
result:
ok single line: '534391186'
Test #7:
score: 10
Accepted
time: 583ms
memory: 2948kb
input:
2 53954 706803678 802362985 892644371 953855359 196462821 817301757 409460796 773943961 488763959 40...
output:
497979099 497530880
result:
ok 2 lines
Test #8:
score: 10
Accepted
time: 132ms
memory: 3180kb
input:
2 34643 15 50 98 93 77 31 43 84 90 6 24 14 37 73 29 43 9 4 8 14 31 91 97 72 23 73 68 70 51 78 2 19 1...
output:
50 50
result:
ok 2 lines
Test #9:
score: 10
Accepted
time: 140ms
memory: 4300kb
input:
1 100000 93 758062633 88 981601925 22 28054989 72 269036456 41 161626551 15 521363191 3 244982120 50...
output:
23
result:
ok single line: '23'
Test #10:
score: 10
Accepted
time: 492ms
memory: 4404kb
input:
1 100000 223444244 49 154763608 49 914282513 57 594690778 49 46129939 20 592083152 16 459436308 39 6...
output:
499790184
result:
ok single line: '499790184'
Extra Test:
score: 0
Extra Test Passed