QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600804#9123. Kth SumpeterWA 7ms5928kbC++141.3kb2024-09-29 19:25:022024-09-29 19:25:02

Judging History

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

  • [2024-09-29 19:25:02]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:5928kb
  • [2024-09-29 19:25:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,int> pii;

const int maxn=5e4+5;
const int maxm=4e6+5;
int a[maxn],b[maxn],c[maxn],d[maxm],cnt=0;
int pos[maxn];
priority_queue<pii> que;

int main(){
	
	int n,k,blk;
	
	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);
	
	blk=sqrt(1ll*n*k);
	
	for(int i=1;i<=n;i++){
		que.push(make_pair(-(b[i]+c[1]),i));
		pos[i]=1;
	}
	
	while(cnt<blk&&(!que.empty())){
		int x=que.top().second;
		que.pop();
		d[++cnt]=b[x]+c[pos[x]];
		pos[x]++;
		if(pos[x]<=n) que.push(make_pair(-(b[x]+c[pos[x]]),x));
	}
	
	ll l=0,r=1ll*a[n]+b[n]+c[n],ret;
	
	while(l<=r){
		ll mid=(l+r)>>1;
		int t=upper_bound(a+1,a+n+1,mid-d[cnt])-a-1;
		if(1ll*t*cnt>=mid){
			ret=mid;
			r=mid-1;
			continue;
		}
		ll sum=0;
		int now=n;
		for(int i=1;i<=cnt&&sum<k&&now>t;i++){
			while(now>t&&1ll*d[i]+a[now]>mid) now--;
			sum+=(now-t);
		}
		for(int i=1;i<=t&&sum<k;i++){
			now=n;
			for(int j=1;j<=n&&now&&sum<k;j++){
				while(now&&1ll*a[i]+b[i]+c[now]>mid) now--;
				sum+=now;
			}
		}
		if(sum>=k){
			ret=mid;
			r=mid-1;
		}else l=mid+1;
	}
	
	printf("%lld\n",ret);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 4
1 2
3 4
5 6

output:

10

result:

ok "10"

Test #2:

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

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: 1ms
memory: 5908kb

input:

1 1
1000000000
1000000000
1000000000

output:

3000000000

result:

ok "3000000000"

Test #4:

score: -100
Wrong Answer
time: 7ms
memory: 4156kb

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:

1286614752

result:

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