QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#794095#9123. Kth SumchidmTL 7ms4216kbC++141.8kb2024-11-30 10:57:472024-11-30 10:57:48

Judging History

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

  • [2024-11-30 10:57:48]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:4216kb
  • [2024-11-30 10:57:47]
  • 提交

answer

#include <bits/stdc++.h>
#define pll pair<long long,long long>

using namespace std;
vector<long long>arr;
priority_queue<pll,vector<pll>,greater<pll>>q;
long long n,k,a[50005],b[50005],c[50005],lim,len,it[50005],it1,cnt,l,r,mid,ans;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)cin>>c[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    sort(c+1,c+n+1);
    for(int i=1;i<=n;i++)
    {
        it[i]=1;
        q.push({b[i]+c[1],i});
    }
    lim=min(n*n*n,1ll*5000000);
    pair<long long,long long>b1,b2;
    while(!q.empty())
    {
        b1=q.top();
        q.pop();
        if(!q.empty())b2=q.top();
        else b2.first=1e18;
        while(b[b1.second]+c[it[b1.second]]<=b2.first&&it[b1.second]<=n)
        {
            len++;arr.push_back(b[b1.second]+c[it[b1.second]]);
            it[b1.second]++;
            if(len>=lim||it[b1.second]>n)break;
        }
        if(len>=lim)break;
        if(it[b1.second]<=n)q.push({b[b1.second]+c[it[b1.second]],b1.second});
    }
    l=0;r=1e18;
    while(l<=r)
    {
        mid=(l+r)/2;cnt=0;
        for(int i=1;i<=n;i++)
            if(a[i]+arr[len-1]<mid)
        {
            it1=n;
            for(int j=1;j<=n;j++)
            {
                while(it1)
                {
                    if(a[i]+b[j]+c[it1]<mid)break;
                    it1--;
                }
                cnt+=it1;
            }
        }
        else
        {
            it1=lower_bound(arr.begin(),arr.end(),mid-a[i])-arr.begin();
            cnt+=it1;
        }
        if(cnt>=k)r=mid-1;
        else {ans=mid;l=mid+1;}
    }
    cout<<ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3732kb

input:

2 4
1 2
3 4
5 6

output:

10

result:

ok "10"

Test #2:

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

input:

10 40
11 9 13 12 15 11 11 2 11 17
3 1 10 2 12 18 9 11 11 15
14 9 4 14 16 9 20 2 1 18

output:

14

result:

ok "14"

Test #3:

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

input:

1 1
1000000000
1000000000
1000000000

output:

3000000000

result:

ok "3000000000"

Test #4:

score: 0
Accepted
time: 7ms
memory: 4216kb

input:

314 12491830
429392519 92131736 9460149 448874040 5326166 804308891 571581523 580832602 110825817 11150177 47845585 886171410 888601860 633656718 879205016 333690452 739013504 118317331 8289119 502971381 486014573 167383690 96016893 556946780 634198668 389358242 984894049 735281439 58642904 22106451...

output:

1346801336

result:

ok "1346801336"

Test #5:

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

input:

34 34490
133495256 283197838 857697935 858259368 959152648 301897236 990604260 865643006 704101978 322295867 324109158 258113372 423370893 16000407 224364583 353708691 265955784 183826167 813127458 476308169 634865805 973017138 197716378 674895784 956141489 277068847 534893183 817797721 662940992 82...

output:

2149314674

result:

ok "2149314674"

Test #6:

score: 0
Accepted
time: 3ms
memory: 3728kb

input:

162 3892887
763969065 810700429 42372207 636240914 502913712 840954780 778223217 445420701 2410846 338474264 231776510 588586138 368205344 103376804 569524150 783792347 87865355 617931224 986562016 523273886 488749745 483683293 299415863 792844787 204455380 164779452 748455830 195281294 930802591 80...

output:

2182951602

result:

ok "2182951602"

Test #7:

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

input:

86 413467
763039094 633170311 595642701 709189753 825336413 674979614 902278662 98827324 300719716 354652661 803007374 960528102 608007086 822156983 251120206 213876002 319840344 52036279 86367645 865206894 637600977 362945669 769711568 205761081 157801980 52490057 298454964 572764868 125035261 4872...

output:

1675510101

result:

ok "1675510101"

Test #8:

score: 0
Accepted
time: 2ms
memory: 3848kb

input:

214 7057935
98545611 529269121 443880485 487171300 369097477 582633376 321301399 678605020 893995877 2234839 79270945 291000867 847808829 204500671 596279774 233894241 478186405 117545115 891205983 838543682 491484917 873611825 871411053 323710085 406115873 645233371 143421391 950248441 24300640 758...

output:

1763767750

result:

ok "1763767750"

Test #9:

score: -100
Time Limit Exceeded

input:

9429 823330096
710308717 885443360 151359742 257927627 89698847 133943367 458101850 441715448 448225213 867533556 948805555 168922334 660173729 242187286 990107147 920584508 611308123 525304427 558566303 443722397 295118124 112161359 258379911 198998755 698515100 523982637 41263636 383698580 8552056...

output:


result: