QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420177#8370. T3by_chance0 37ms6000kbC++141.0kb2024-05-24 15:05:392024-05-24 15:05:40

Judging History

你现在查看的是最新测评结果

  • [2024-05-24 15:05:40]
  • 评测
  • 测评结果:0
  • 用时:37ms
  • 内存:6000kb
  • [2024-05-24 15:05:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,m,a[N],b[N],va,vb,x[N],y[N];
bool check(int lim){
    ll sum=1ll*n*m;
    for(int i=n,j=0;i>=1;i--){
        while(j<m&&a[i]+b[j+1]<=lim)++j;
        x[i]=j;sum-=x[i];
    }
    for(int i=m,j=0;i>=1;i--){
        while(j<m&&b[i]+a[j+1]<=lim)++j;
        y[i]=j;
    }
    ll mx=sum;int flag=0;
    for(int i=1,j=0;i<=n;i++){
        sum+=x[i]+j-m;
        while(j<m&&y[j+1]+i-n>=0)sum+=y[++j]+i-n;
        if(sum>=mx)mx=sum,flag=(va<=i&&vb<=j);
    }
    return flag;
}
int main(){
    // freopen("chess.in","r",stdin);
    // freopen("chess.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",a+i);va=a[1];
    for(int i=1;i<=m;i++)scanf("%d",b+i);vb=b[1];
    sort(a+1,a+n+1);va=lower_bound(a+1,a+n+1,va)-a;
    sort(b+1,b+m+1);vb=lower_bound(b+1,b+m+1,vb)-b;
    int L=0,R=a[va]+b[vb];
    while(L<R){
        int mid=(L+R)>>1;
        if(check(mid))R=mid;else L=mid+1;
    }
    printf("%d\n",R);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 14
Accepted
time: 1ms
memory: 5856kb

input:

3 4
5793102 5457652 10631669
14037022 24564522 19828638 16740187

output:

19830124

result:

ok 1 number(s): "19830124"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5836kb

input:

4 4
24461545 7466923 15331834 20936291
21465585 2271163 23099576 8980678

output:

29916969

result:

ok 1 number(s): "29916969"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5844kb

input:

4 1
46521231 59300629 47833220 9231226
69485861

output:

116007092

result:

ok 1 number(s): "116007092"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

4 1
4956725 7458189 2245373 5089414
71658100

output:

76614825

result:

ok 1 number(s): "76614825"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3900kb

input:

4 1
4140322 4479566 40826591 29747993
34463254

output:

38603576

result:

ok 1 number(s): "38603576"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3960kb

input:

3 3
8632467 13707438 3309699
48647378 18658100 26245660

output:

34878127

result:

ok 1 number(s): "34878127"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

4 4
15678597 4645170 12200683 25429499
28590191 25995901 22163115 9233748

output:

37841712

result:

ok 1 number(s): "37841712"

Test #8:

score: -14
Wrong Answer
time: 1ms
memory: 5848kb

input:

3 4
26636342 7115004 14212520
9334410 15565174 17372159 12106004

output:

26318524

result:

wrong answer 1st numbers differ - expected: '24487163', found: '26318524'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 11
Accepted
time: 19ms
memory: 4776kb

input:

58907 56480
44575563 540879 28467036 43621838 25515388 10048620 4501896 38628765 39419406 29497118 41954017 917402 20191987 40236908 12585166 22986979 1764011 21587278 32837245 20261107 20671792 37064770 22652008 6411880 34950023 5163325 17409659 46335787 11065741 6440463 44544150 13934453 19477226 ...

output:

23107969

result:

ok 1 number(s): "23107969"

Test #12:

score: -11
Wrong Answer
time: 37ms
memory: 5752kb

input:

189469 57603
28875640 6205004 21110951 23480849 10442288 1789266 29632233 2628015 1177308 14489813 11239759 18891059 18357357 30758696 25588314 22649200 22717678 14167578 9873586 28217823 17553393 22985060 22126753 15538086 23430634 14333822 29323385 6702484 18708803 24043666 22202322 14747587 38164...

output:

21643852

result:

wrong answer 1st numbers differ - expected: '15556246', found: '21643852'

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 15
Accepted
time: 0ms
memory: 3808kb

input:

3 10
24332538 25602471 54833728
7466852 20176810 23770883 13240181 15036268 16178071 19850557 11751859 12686516 11159532

output:

31799390

result:

ok 1 number(s): "31799390"

Test #22:

score: 0
Accepted
time: 1ms
memory: 5844kb

input:

4 9
14880669 10667567 7977836 1882967
80951479 5481207 15459896 52525030 28052486 14797866 34391066 58754229 27619130

output:

38286697

result:

ok 1 number(s): "38286697"

Test #23:

score: -15
Wrong Answer
time: 0ms
memory: 3820kb

input:

6 5
1410209 331777 605947 756537 156780 131599
28694381 10823646 29868509 9541258 22217924

output:

22823871

result:

wrong answer 1st numbers differ - expected: '22549701', found: '22823871'

Subtask #4:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 1ms
memory: 6000kb

input:

557 24
944055 6651285 6872647 7501680 6728901 5684173 78312 872911 5349349 5834868 1104965 5034609 943636 6298640 4862332 6874311 4925018 7027588 6656184 1303888 1092633 6129416 3629195 5717171 4703294 6929327 6147793 2666674 4531679 3785633 7473654 274978 7723474 1969517 3520566 5338238 380308 7691...

output:

49006070

result:

wrong answer 1st numbers differ - expected: '41467742', found: '49006070'

Subtask #5:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 0ms
memory: 3768kb

input:

557 24
944055 6651285 6872647 7501680 6728901 5684173 78312 872911 5349349 5834868 1104965 5034609 943636 6298640 4862332 6874311 4925018 7027588 6656184 1303888 1092633 6129416 3629195 5717171 4703294 6929327 6147793 2666674 4531679 3785633 7473654 274978 7723474 1969517 3520566 5338238 380308 7691...

output:

49006070

result:

wrong answer 1st numbers differ - expected: '41467742', found: '49006070'

Subtask #6:

score: 0
Wrong Answer

Test #64:

score: 0
Wrong Answer
time: 1ms
memory: 5936kb

input:

557 24
944055 6651285 6872647 7501680 6728901 5684173 78312 872911 5349349 5834868 1104965 5034609 943636 6298640 4862332 6874311 4925018 7027588 6656184 1303888 1092633 6129416 3629195 5717171 4703294 6929327 6147793 2666674 4531679 3785633 7473654 274978 7723474 1969517 3520566 5338238 380308 7691...

output:

49006070

result:

wrong answer 1st numbers differ - expected: '41467742', found: '49006070'