QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#794083 | #9123. Kth Sum | chidm | WA | 19ms | 69540kb | C++14 | 1.7kb | 2024-11-30 10:47:01 | 2024-11-30 10:47:01 |
Judging History
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)
{
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=upper_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+1;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
2 4 1 2 3 4 5 6
output:
10
result:
ok "10"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3732kb
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: 3660kb
input:
1 1 1000000000 1000000000 1000000000
output:
3000000000
result:
ok "3000000000"
Test #4:
score: -100
Wrong Answer
time: 19ms
memory: 69540kb
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:
37458005
result:
wrong answer 1st words differ - expected: '1346801336', found: '37458005'