UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#198040#3456. 跑步比赛OoXiao_QioO100853ms2884kbC++1.2kb2023-11-19 13:42:362023-11-19 16:05:21

answer

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'
#define hh cout<<endl;
#define No cout<<"No"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define YES cout<<"YES"<<endl;
typedef long long ll;
int n;
int v[100001],w[100001];
vector<int> a,b;
bool cmpa(int a,int b)
{
    return w[a]>w[b];
}
bool cmpb(int a,int b)
{
    return (v[a]+w[a])>(v[b]+w[b]);
}
bool check(ll x)
{
    a.clear();
    b.clear();
    int i;
    for(i=1;i<=n;i++)
    {
        if(v[i]<x)
            a.push_back(i);
        else
            b.push_back(i);
    }
    if(a.size()>b.size())
        return 0;
    sort(a.begin(),a.end(),cmpa);
    sort(b.begin(),b.end(),cmpb);
    int l = a.size();
    for(i=0;i<l;i++)
    {
        int t = v[b[i]]-w[a[i]]+w[b[i]];
        if(t<x)
            return 0;
    }
    return 1;
}
void solve()
{
    cin>>n;
    int i;
    for(i=1;i<=n;i++)
        cin>>v[i]>>w[i];
    int l = 1,r = 1e9;
    while(l<r)
    {
        ll mid = (l+r+1)/2;
        if(check(mid))
            l = mid;
        else
            r = mid-1;
    }
    cout<<l<<endl;
    return;
}
signed main()
{
    int T = 1;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

详细

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

Test #1:

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

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

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

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

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

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

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: 324ms
memory: 2116kb

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: 72ms
memory: 2276kb

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: 147ms
memory: 2884kb

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: 310ms
memory: 2624kb

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