QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#724180#9123. Kth Sum11d10xyWA 14ms3976kbC++141.5kb2024-11-08 10:36:492024-11-08 10:36:49

Judging History

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

  • [2024-11-08 10:36:49]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:3976kb
  • [2024-11-08 10:36:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64=long long;
constexpr int B=200;
int n,K,a[50010],b[50010],c[50010];
namespace pre{
vector<int>val;
priority_queue<pair<int,int>>q;
int cur[50010];
inline void ins(int i){
   if(cur[i]>=n)return;
   cur[i]++;
   q.emplace(-(b[i]+c[cur[i]]),i);
}
void work(){
   for(int i=1;i<=n;i++)ins(i);
   for(;!q.empty()&&val.size()<5000000;){
      auto X=q.top();q.pop();
      val.push_back(-X.first),ins(X.second);
   }
}
}
int calc(i64 v){
   int res=0;
   for(int i=1,j=n;i<=n;i++){
      for(;j>=1&&b[i]+c[j]>v;j--);
      res=min(res+j,K);
   }return res;
}
bool check(i64 M){
   if(n<=B){
      int s=0;
      for(int i=1;i<=n;i++){
         s+=calc(M-a[i]);
         if(s>=K)return true;
      }return false;
   }
   int f0=calc(M-a[B]);
   if(f0>=(K-1)/B+1)return true;
   int s=f0;
   for(int i=1;i<B;i++){
      s+=calc(M-a[i]);
      if(s>=K)return true;
   }
   for(int i=B+1;i<=n;i++){
      s+=upper_bound(begin(pre::val),end(pre::val),M-a[i])-begin(pre::val);
      if(s>=K)return true;
   }
   return false;
}
int main(){
   scanf("%d%d",&n,&K);
   for(int i=1;i<=n;i++)scanf("%d",&a[i]);
   for(int i=1;i<=n;i++)scanf("%d",&b[i]);
   for(int i=1;i<=n;i++)scanf("%d",&c[i]);
   sort(a+1,a+n+1),sort(b+1,b+n+1),sort(c+1,c+n+1);
   i64 l=0,r=3000000000;
   while(l<r){
      i64 mid=l+r>>1;
      if(check(mid))r=mid;
      else l=mid+1;
   }
   printf("%lld",l);
   return 0;
}

詳細信息

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: 3868kb

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: 3820kb

input:

1 1
1000000000
1000000000
1000000000

output:

3000000000

result:

ok "3000000000"

Test #4:

score: -100
Wrong Answer
time: 14ms
memory: 3976kb

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:

1456809629

result:

wrong answer 1st words differ - expected: '1346801336', found: '1456809629'