QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#875527 | #9123. Kth Sum | SFlyer | WA | 6ms | 4224kb | C++14 | 1.6kb | 2025-01-29 22:20:07 | 2025-01-29 22:20:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e4+4;
int n,K,B,ln;
ll a[N],b[N],c[N],f[N];
bool chk(ll x){
int cnt=0;
for (int i=1; i<=B && i<=n; i++){
for (int j=1,k=n; j<=n; j++){
while (k && a[i]+b[j]+c[k]>x){
k--;
}
cnt+=k;
if (cnt>=K) return 0;
}
}
for (int i=B+1,j=ln; i<=n; i++){
while (j && a[i]+f[j]>x){
j--;
}
cnt+=j;
if (cnt>=K) return 0;
}
return 1;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>K;
B=sqrt(K/n)+1;
ln=min(K/B+1ll,1ll*n*n);
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+1+n);
sort(b+1,b+1+n);
sort(c+1,c+1+n);
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> q;
for (int i=1; i<=n; i++){
q.push({b[i]+c[1],1});
}
for (int i=1; i<=ln; i++){
auto x=q.top();
q.pop();
f[i]=x.first;
if (x.second<n){
q.push({x.first+c[x.second+1]-c[x.second],x.second+1});
}
}
ll l=a[1]+b[1]+c[1]-1,r=a[n]+b[n]+c[n]+1;
while (l+1<r){
ll mid=l+r>>1;
if (chk(mid)){
l=mid;
}
else{
r=mid;
}
}
cout<<l+1<<"\n";
return 0;
}
// TRY! TRY! TRY!
/*
Think twice before coding. Have you overkilled?
Think twice before submitting.
Check on the samples and constraints carefully.
*/
/*
Be brave to guess.
Is your former/first approach correct?
Follow your intuition.
Use a notebook to note down your ideas and check whether they are correct.
*/
/*
A simple brute force may work? There is some limit on the answer?
Try to find patterns.
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
2 4 1 2 3 4 5 6
output:
10
result:
ok "10"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
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: 3712kb
input:
1 1 1000000000 1000000000 1000000000
output:
3000000000
result:
ok "3000000000"
Test #4:
score: -100
Wrong Answer
time: 6ms
memory: 4224kb
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:
1692391195
result:
wrong answer 1st words differ - expected: '1346801336', found: '1692391195'