QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#518543#5076. Prof. Pang and AntszhouhuanyiWA 1ms5912kbC++141.8kb2024-08-13 21:50:142024-08-13 21:50:14

Judging History

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

  • [2024-08-13 21:50:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5912kb
  • [2024-08-13 21:50:14]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 300000
using namespace std;
long long read()
{
	char c=0;
	long long sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct reads
{
	long long l,r;
	int sz;
};
reads tong[N+1];
int T,n,l,r,a[N+1],length;
long long m,ans;
long long get_rk(long long l,long long r,long long d,long long k)
{
	return l+(k+d-1)/d-1;
}
long long calc(long long l1,long long r1,int d1,long long l2,long long r2,int d2)
{
	if (d1<=d2) return l1+r2;
	else
	{
		if ((r1-l1+1)*d1>=(r2-l2+1)*d2) return get_rk(l1,r1,d1,(r2-l2)*d2+1)+r2;
		else return l2+get_rk(l2,r2,d2,(r1-l1+1)*d1);
	}
}
int main()
{
	long long ps,d;
	int ds;
	T=read();
	while (T--)
	{
		n=read(),m=read(),length=1,ans=0;
		for (int i=1;i<=n;++i) a[i]=read();
		sort(a+1,a+n+1);
		for (int i=1;i<=n;++i)
			if (m)
			{
				if (i==n) d=m/i;
				else d=min(m/i,(long long)(a[i+1]-a[i]));
				tong[++length]=(reads){a[i],a[i]+d-1,i},m-=d*i;
			}
		if (m) tong[++length]=(reads){a[n],a[n],(int)(m)};
		l=2,r=length;
		while (l<=r)
		{
			d=min((tong[l].r-tong[l].l+1)*tong[l].sz,(tong[r].r-tong[r].l+1)*tong[r].sz),ans=max(ans,calc(tong[l].l,tong[l].r,tong[l].sz,tong[r].l,tong[r].r,tong[r].sz));
			if (d==(tong[l].r-tong[l].l+1)*tong[l].sz&&d==(tong[r].r-tong[r].l+1)*tong[r].sz) l++,r--;
			else if (d==(tong[l].r-tong[l].l+1)*tong[l].sz)
			{
				l++,tong[r].r-=(d+tong[r].sz-1)/tong[r].sz,ds=d%tong[r].sz;
				if (tong[r].l>tong[r].r) r--;
				if (ds) ps=tong[r].r+1,tong[++r]=(reads){ps,ps,ds};
			}
			else
			{
				r--,tong[l].l+=(d+tong[l].sz-1)/tong[l].sz,ds=d%tong[l].sz;
				if (tong[l].l>tong[l].r) l++;
				if (ds) ps=tong[l].l-1,tong[--l]=(reads){ps,ps,ds};
			}
		}
		printf("%lld\n",ans+2);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 4
1 2
3 10
1 2 3
5 1
1 2 3 4 5

output:

6
9
4

result:

ok 3 number(s): "6 9 4"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5912kb

input:

1
1 100000000000000
1000000000

output:

100002000000001

result:

wrong answer 1st numbers differ - expected: '200000000000000', found: '100002000000001'