QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250467#7678. The Gameucup-team2279WA 0ms3428kbC++141.0kb2023-11-13 10:16:532023-11-13 10:16:53

Judging History

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

  • [2023-11-13 10:16:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3428kb
  • [2023-11-13 10:16:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
void solve(){
	int n,m,cnt=0;
	cin>>n>>m;
	vector<int> ans,a(n),b(m);
	for(int&x:a) cin>>x;
	for(int&x:b) cin>>x;
	sort(a.rbegin(),a.rend());
	sort(b.rbegin(),b.rend());
	for(int i=0;i<m;i++){
		if(a[i]>b[i]){
			cout<<"-1\n";
			return;
		}
		cnt+=b[i]-a[i];
		if(n-cnt<m){
			cout<<"-1\n";
			return;
		}
	}
	multiset<int> s(begin(a),begin(a)+m),t(begin(a)+m,end(a));
	for(;n-cnt>m;n--){
		if(t.empty()){
			cout<<"-1\n";
			return;
		}
		int x=*t.begin();
		ans.push_back(x++);
		t.erase(t.begin());
		if(x>*s.begin()) cnt--,s.erase(s.begin()),s.insert(x),t.insert(x-1);
		else t.insert(x);
		t.erase(t.begin());
	}
	int p=0;
	for(int x:s) a[p++]=x;
	reverse(begin(a),begin(a)+m);
	for(int i=0;i<m;i++){
		if(a[i]>b[i]){
			cout<<"-1\n";
			return;
		}
		while(a[i]<b[i]) ans.push_back(a[i]++);
	}
	cout<<n-m<<"\n";
	for(int x:ans) cout<<x<<" ";
	cout<<"\n";
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3428kb

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 3 
-1
2
2 4 4 
2
1 1 1 2 3 
0
1 1 
-1

result:

wrong answer Wrong answer, number of operation is not correct (test case 1)