QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620929#7678. The Gamety09RE 1ms3580kbC++171.7kb2024-10-07 22:24:492024-10-07 22:24:50

Judging History

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

  • [2024-10-07 22:24:50]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3580kb
  • [2024-10-07 22:24:49]
  • 提交

answer

// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(nullptr),cout.tie(nullptr)
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define T() int ____t;cin>>____t;while(____t--)
using namespace std;
constexpr int N=3e5+10,mod=1e9+7;

#define int ll
void solve(){
	int n,m,sumb(0),suma(0);
	cin>>n>>m;
	vector<int>a(n),b(m);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<m;i++) cin>>b[i];
	sort(a.begin(),a.end(),greater());
	sort(b.begin(),b.end(),greater());
	vector<int>ans;
	priority_queue<int,vector<int>,greater<> >qa;//a中前m大的数
	priority_queue<int,vector<int>,greater<> >qx;//a中小的
	int cnt=0;//
	for(int i=0;i<m;i++){
		if(a[i]<=b[i]){
			suma+=a[i];
			sumb+=b[i];
			qa.push(a[i]);
			cnt+=b[i]-a[i];
		}else{
			cout<<-1<<endl;
			return;
		}
	}
	
	if(sumb-suma>n-m){//所需操作次数 > 能够操作次数
		cout<<-1<<endl;
		return;
	}
	for(int i=m;i<n;i++){
		qx.push(a[i]);
	}
	while(sumb-suma<n-m){//所需操作次数 < 能够操作次数
		n--;
		int x=qx.top();
		qx.pop();
		ans.push_back(x);
		
		x++;
		if(x<=qa.top()){
			qx.push(x);
			qx.pop();
		}
		else{
			int y=qa.top();
			qa.pop();
			qx.push(y);
			qa.push(x);
			suma-=y;
			suma+=x;
			int nowy=qa.top();
			if(nowy>b[m-1]){
				cout<<-1<<endl;
				return;
			}
			qx.pop();
		}
	}
	int j=m-1;
	while(qa.size()){
		int x=qa.top();
		qa.pop();
		while(x<b[j]){
			ans.push_back(x);
			x++;
		}
		j--;
	}
	cout<<ans.size()<<endl;
	for(auto i:ans){
		cout<<i<<" ";
	}cout<<endl;
}
signed main()
{
	ios;
	T()
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3580kb

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
Runtime Error

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:


result: