QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679732#7678. The GameDisplace_#WA 1ms5680kbC++141.5kb2024-10-26 18:19:362024-10-26 18:19:37

Judging History

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

  • [2024-10-26 18:19:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5680kb
  • [2024-10-26 18:19:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0;char c=getchar();bool f=0;
	for(;c<'0'||c>'9';c=getchar()) f|=(c=='-');
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	return (f)?(-x):x;
}
const int N=3e5+86;
int T,n,m,a[N],b[N],sm1,sm2,sm3;
int op1,op2,as[N],k=0;
priority_queue<int, vector<int>, greater<int> > s1,s2;
int main()
{
	T=read();
	while(T--)
	{
		while(s1.size()) s1.pop();
		while(s2.size()) s2.pop();
		sm1=sm2=sm3=0;k=0;
		n=read();m=read();
		for(int i=1;i<=n;i++) a[i]=read();
		for(int i=1;i<=m;i++) b[i]=read(),sm2+=b[i];
		sort(a+1,a+1+n);
		sort(b+1,b+1+m);
		for(int i=n-m+1;i<=n;i++) sm1+=a[i];
		op2=sm2-sm1;
		op1=(n-m)-op2;
		if(op1<0||op2>(n-m)||a[n]>b[m])
		{
			cout<<"-1"<<endl;
			continue;
		}
		for(int i=1;i<=n-m;i++) s1.push(a[i]);
		for(int i=n-m+1;i<=n;i++) s2.push(a[i]);
		int kb=1;
		while(op1+op2>0)
		{
//			cout<<op1<<" "<<op2<<endl;
			while(op1&&s1.size()&&s1.top()<s2.top())
			{
				int te=s1.top();
				as[++k]=te;
				s1.pop();
				s1.push(te+1);
				s1.pop();
				op1--;
			}
			int te=s2.top();
			while(te==b[kb]&&kb<=m)
			{
				s2.pop();
				te=s2.top();
				kb++;
			}
			if(kb>m||s2.empty()||s1.empty()||op1<=0||op2<=0) break;
			if(op2) 
			{
				s2.pop();
				as[++k]=te;
				s2.push(te+1);
				s1.pop();
				op2--;
			}
			
		}
		if(op1||op2) cout<<"-1"<<endl;
		else 
		{
			cout<<n-m<<endl;
			for(int i=1;i<=n-m;i++) cout<<as[i]<<" ";
			cout<<endl;
		}
		
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5680kb

input:

6
5 3
1 2 2 3 3
2 3 4
4 2
1 2 2 4
2 4
5 2
2 3 3 4 4
5 5
6 1
1 1 1 1 1 1
4
4 2
1 1 1 2
2 2
4 1
1 1 1 1
2

output:

-1
-1
-1
-1
2
1 1 
-1

result:

wrong answer Jury has answer but participant has not (test case 1)