QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#712157#9123. Kth SumtobieWA 44ms13296kbC++142.7kb2024-11-05 14:43:072024-11-05 14:43:07

Judging History

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

  • [2024-11-05 14:43:07]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:13296kb
  • [2024-11-05 14:43:07]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define int long long
bool st_;
const int N=50009,M=5e6+9,B=2000;
int n,K,a[N],b[N],c[N];
struct Node{
	int r,v;
	Node(){}
	inline Node(int r_,int v_)
	{
//		cerr<<"Ins "<<r_<<" "<<v_<<endl;
		r=r_,v=v_;
	}
};
Node va[M],vb[M],vc[M];
int va_cnt,vb_cnt,vc_cnt;

const int NN=65539;
int buc[NN];
Node fz[M];
void quick_sort(Node *a,int m)
{
	for(int i=0;i<NN;i++) buc[i]=0;
	for(int i=1;i<=m;i++) buc[a[i].r&65535]++;
	for(int i=1;i<NN;i++) buc[i]+=buc[i-1];
	for(int i=m;i>=1;i--) fz[(buc[a[i].r&65535]--)]=a[i];
	
	for(int i=0;i<NN;i++) buc[i]=0;
	for(int i=1;i<=m;i++) buc[fz[i].r>>16]++;
	for(int i=1;i<NN;i++) buc[i]+=buc[i-1];
	for(int i=m;i>=1;i--) a[(buc[fz[i].r>>16]--)]=fz[i];
}

bool check(int lim)
{
//	cerr<<"check "<<lim<<endl;
	int ans=0;
	va_cnt=vb_cnt=vc_cnt=0;
	for(int i=1;i<=n&&i<=B;i++)
	{
		int st=n+1;
		for(int j=1;j<=n&&i*j*j<=K;j++)
		if(a[i]+b[j]<=lim)
		{
			if(lim-a[i]-b[j]<=c[n]) vc[++vc_cnt]=Node(lim-a[i]-b[j],1),st=j+1;
			else ans+=n;
		}
		else break;
		if(st!=n+1)
		{
			int cnt=0;
			for(int j=1;j<=n&&i*j*j<=K;j++)
			if(b[st]+a[i]+c[j]<=lim)
			{
				if(lim-a[i]-c[j]<=b[n])	vb[++vb_cnt]=Node(lim-a[i]-c[j],1),cnt++;
				else ans+=n;
			}
			else break;
			if(b[st]-1<=b[n]) vb[++vb_cnt]=Node(b[st]-1,-cnt);
			else ans-=n*cnt;
		}
	}
	if(B<=n)
	{
		int cnt=0;
		for(int i=1;i<=n&&B*i<=K;i++)
		{
			for(int j=1;j<=n&&i*j*B<=K;j++)
			if(a[B+1]+b[i]+c[j]<=lim)
			{
				if(lim-b[i]-c[j]<=a[n])	va[++va_cnt]=Node(lim-b[i]-c[j],1);
				else ans+=n;
			}
			else break;
		}
		if(a[B+1]-1<=a[n]) va[++va_cnt]=Node(a[B+1]-1,-cnt);
		else ans-=n*cnt;
	}
	quick_sort(va,va_cnt);
	quick_sort(vb,vb_cnt);
	quick_sort(vc,vc_cnt);
//	cerr<<va_cnt<<" "<<vb_cnt<<" "<<vc_cnt<<endl;
	for(int i=1,j=0;i<=n+1;i++)
	{
		while(j<va_cnt&&va[j+1].r<a[i]) j++,ans+=va[j].v*(i-1);
	}
	if(ans>=K) return 0;
	for(int i=1,j=0;i<=n+1;i++)
	{
		while(j<vb_cnt&&vb[j+1].r<b[i]) j++,ans+=vb[j].v*(i-1);
	}
	if(ans>=K) return 0;
	for(int i=1,j=0;i<=n+1;i++)
	{
		while(j<vc_cnt&&vc[j+1].r<c[i]) j++,ans+=vc[j].v*(i-1);
	}
	return ans<K;
}
bool ed_;
signed main()
{
	cerr<<(&ed_-&st_)/1048576.0<<" Mib\n";
//	freopen("set.in","r",stdin);
//	freopen("set.out","w",stdout);
	scanf("%lld%lld",&n,&K);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
	for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	a[n+1]=b[n+1]=c[n+1]=5e9+100;
	int L=-1,R=a[n]+b[n]+c[n],res=0;
	while(L<=R)
	{
		int mid=(L+R)/2;
		if(check(mid)) res=mid,L=mid+1;
		else R=mid-1;
	}
	printf("%lld\n",res+1);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 12152kb

input:

2 4
1 2
3 4
5 6

output:

10

result:

ok "10"

Test #2:

score: 0
Accepted
time: 0ms
memory: 8064kb

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: 8ms
memory: 6020kb

input:

1 1
1000000000
1000000000
1000000000

output:

3000000000

result:

ok "3000000000"

Test #4:

score: 0
Accepted
time: 44ms
memory: 13296kb

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:

1346801336

result:

ok "1346801336"

Test #5:

score: -100
Wrong Answer
time: 8ms
memory: 8040kb

input:

34 34490
133495256 283197838 857697935 858259368 959152648 301897236 990604260 865643006 704101978 322295867 324109158 258113372 423370893 16000407 224364583 353708691 265955784 183826167 813127458 476308169 634865805 973017138 197716378 674895784 956141489 277068847 534893183 817797721 662940992 82...

output:

2111568461

result:

wrong answer 1st words differ - expected: '2149314674', found: '2111568461'