ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#198049 | #3456. 跑步比赛 | CheZiHe929 | 100 | 989ms | 4332kb | C++ | 903b | 2023-11-19 14:02:01 | 2023-11-19 16:06:19 |
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
const int MAXN=1e5+5;
int T;
int n;
int v[MAXN],w[MAXN];
int a[MAXN],b[MAXN];//a no b yes
bool cmpa(int a,int b){return w[a]>w[b];}
bool cmpb(int a,int b){return (w[a]+v[a])>(w[b]+v[b]);}
bool check(int x){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int cnta=0,cntb=0;
for(int i=1;i<=n;i++){
if(v[i]<x)a[++cnta]=i;
else b[++cntb]=i;
}
if(cnta>cntb)return false;
std::sort(a+1,a+cnta+1,cmpa);
std::sort(b+1,b+cntb+1,cmpb);
for(int i=1;i<=cnta;i++){
int now=v[b[i]]-(w[a[i]]-w[b[i]]);
if(now<x)return false;
}
return true;
}
signed main(){
std::cin>>T;
while(T--){
std::cin>>n;
for(int i=1;i<=n;i++)std::cin>>v[i]>>w[i];
int l=1,r=1e9;
while(l<r){
int mid=(l+r+1)/2;
if(check(mid))l=mid;
else r=mid-1;
}
std::cout<<l<<endl;
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 4ms
memory: 2780kb
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: 4ms
memory: 2780kb
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: 48ms
memory: 2780kb
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: 46ms
memory: 2784kb
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: 5ms
memory: 2792kb
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: 2ms
memory: 2792kb
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: 335ms
memory: 3624kb
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: 80ms
memory: 3800kb
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: 146ms
memory: 4332kb
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: 319ms
memory: 4332kb
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