QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248089#7678. The GametrigriffinWA 11ms5752kbC++142.2kb2023-11-11 17:26:012023-11-11 17:26:01

Judging History

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

  • [2023-11-11 17:26:01]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:5752kb
  • [2023-11-11 17:26:01]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a[300005],b[300005];
int n;
vector<int>ans;
int get(int cnt,int l)
{
//	cout<<cnt<<' '<<l<<endl;
	if(cnt<l)
		return l;
	else if(cnt>l)
		l=cnt;
	for(int i=l+1;i<n;++i)
	{
		if(a[i]!=a[i-1])
			return i-1;
	}
	return n-1;
}
int main()
{
	int t,m,s0,s;
	cin>>t;
	while(t--)
	{
		ans.clear();
		cin>>n>>m;
		s0=s=0;
		for(int i=0;i<n;++i)
			cin>>a[i];
		sort(a,a+n);
		for(int i=0;i<m;++i)
		{
			cin>>b[i];
		}
		sort(b,b+m);
		bool flag=0;
		for(int i=0;i<m;++i)
		{
			s0+=b[i];
			s+=a[i+n-m];
			if(a[i+n-m]>b[i])
			{
				flag=1;
				break;
			}
		}
		if(flag)	
			cout<<-1<<"\n";
		if(s>s0||n-m<s-s0)
		{
			cout<<-1<<"\n";
			continue;
		}
//		cout<<s0<<' '<<s<<endl;
		int i=0,j=n-1;
		for(int cnt=0;cnt<n-m;++cnt)
		{
//			cout<<i<<endl;
//			cout<<cnt<<' '<<s<<' '<<s0<<endl;
			if(s0<s)
			{
				flag=1;
				break;
			}
			if(s0-s>=n-m-cnt)
			{
//				cout<<i<<endl;
				for(;j>=cnt;--j)
				{
					if(a[j]!=b[j+m-n])
					{
						ans.push_back(a[j]);
						++a[j];
						++s;
						break;
					}
					if(j==cnt)
					{
						flag=1;
						break;
					}
				}
			}
			else
			{
				i=get(cnt,i);
				ans.push_back(a[i]);
				++a[i];
//				cout<<i<<endl;
				if(i>=n-m)
					++s;	
				--i;
//				cout<<cnt<<' '<<s<<' '<<s0<<endl;	
			}
		}
		
		/*
		if(s0-s==1)
		{
			for(;j>=n-m-1;--j)
			{
				if(a[j]!=b[j+m-n])
				{
					ans.push_back(a[j]);
					++a[j];
					++s;
					break;
				}
			}
		}
		else if(s0==s)
		{
//			cout<<a[n-m]<<' '<<a[n-m-1]<<endl;
			if(a[n-m]>a[n-m-1])
				ans.push_back(a[n-m-1]);
			else flag=1;
		}
		*/

//		for(int i=0;i<ans.size();++i)
//			cout<<ans[i]<<' ';
		if(s!=s0)
			flag=1;
		if(flag)
			cout<<-1<<"\n";
		else
		{
			if(n==m)
			{
				flag=0;
				for(int i=0;i<n;++i)
					if(a[i]!=b[i])
					{
						flag=1;
						break;
					}
				if(flag)
					cout<<-1<<"\n";
				else cout<<0<<"\n";
			}
			else
			{
				cout<<n-m<<"\n";
				for(int i=0;i<n-m;++i)
					cout<<ans[i]<<" ";
				cout<<"\n";
			}
//			cout<<"\n";
		}
	}
	return 0;
}

詳細信息

Test #1:

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

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:

2
1 3 
-1
3
2 4 4 
5
1 1 1 2 3 
2
1 1 
-1

result:

ok ok (6 test cases)

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 5752kb

input:

7056
4 3
1 1 1 1
1 1 1
4 3
1 1 1 1
1 1 2
4 3
1 1 1 1
1 1 3
4 3
1 1 1 1
1 1 4
4 3
1 1 1 1
1 1 5
4 3
1 1 1 1
1 1 6
4 3
1 1 1 1
1 2 2
4 3
1 1 1 1
1 2 3
4 3
1 1 1 1
1 2 4
4 3
1 1 1 1
1 2 5
4 3
1 1 1 1
1 2 6
4 3
1 1 1 1
1 3 3
4 3
1 1 1 1
1 3 4
4 3
1 1 1 1
1 3 5
4 3
1 1 1 1
1 3 6
4 3
1 1 1 1
1 4 4
4 3
1 1...

output:

-1
1
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 
-1
-1
-1
1
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

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