QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#794090#9123. Kth SumchidmTL 0ms0kbC++141.7kb2024-11-30 10:52:292024-11-30 10:52:29

Judging History

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

  • [2024-11-30 10:52:29]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-30 10:52:29]
  • 提交

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(1)
    {
        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)break;
        }
        if(len>=lim)break;
        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: 0
Time Limit Exceeded

input:

2 4
1 2
3 4
5 6

output:


result: