UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#198102#3456. 跑步比赛BYR_KKK100316ms3540kbC++1.1kb2023-11-19 15:09:322023-11-19 16:11:51

answer

#include <bits/stdc++.h>

const int N = 100010;

int T,n;

struct Node{
    int v,w;
}A[N],B[N];

bool check(int x){
    std::vector <int> p,q;
    for(int i=1;i<=n;i++) if(A[i].v >= x) p.push_back(A[i].v+A[i].w-x);
    for(int i=1;i<=n;i++) if(B[i].v < x) q.push_back(B[i].w);
    if(p.size() < q.size()) return false;
    for(int i=0;i<q.size();i++){
        if(p[i] < q[i]) return false;
    }
    return true;
}

bool cmp(Node a,Node b) {
    return a.w > b.w;
}

bool cmp1(Node a,Node b){
    return (a.v+a.w) > (b.v+b.w);
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    std::cin>>T;
    while(T--){   
        std::cin>>n;
        for(int i=1;i<=n;i++){
            std::cin>>A[i].v>>A[i].w;
            B[i].v = A[i].v;
            B[i].w = A[i].w;
        }
        std::sort(A+1,A+n+1,cmp1);
        std::sort(B+1,B+n+1,cmp);
        int l = 0,r = 0x3f3f3f3f;
        while(l < r){
            int mid = (l+r+1) / 2;
            if(check(mid)) l = mid;
            else r = mid-1;
        }
        std::cout<<l<<'\n';
    }
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1280kb

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: 1280kb

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: 1288kb

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: 2ms
memory: 1284kb

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: 1308kb

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: 0ms
memory: 1308kb

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: 101ms
memory: 2468kb

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: 56ms
memory: 2676kb

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: 74ms
memory: 3420kb

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: 81ms
memory: 3540kb

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