QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466849#7678. The Gameyurongyi#WA 0ms3656kbC++141.3kb2024-07-08 10:59:302024-07-08 10:59:31

Judging History

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

  • [2024-07-08 10:59:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-07-08 10:59:30]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N = 3e5 + 10;
int n, m, a[N], b[N];
vector <int> ans;
priority_queue < int, vector <int>, greater <int> > q;
void work(){
	int sum = 0;
	for(int i = n - m + 1, j = 1; j <= m; i++, j++){
		if(a[i] > b[j]){
			cout << "-1\n";
			return;
		}
		sum += b[j] - a[i]; 
//		cout << sum << endl;
		if(sum > n - m){
			cout << "-1\n";
			return;
		}
	}
	while(!q.empty())
		q.pop();
	for(int i = 1; i <= n - m - sum; i++)
		q.push(a[i]);
	while(q.size() > 1){
		q.push(q.top() + 1);
		q.pop();
		q.pop();
	}
	if(q.top() >= b[1]){
		cout << "-1\n";
		return;
	}
	ans.clear();
	for(int i = 1; i <= n - m - sum; i++)
		ans.push_back(a[i]); 
	for(int i = n - m + 1, j = 1; j <= m; i++, j++){
		for(int k = a[i]; k < b[j]; k++)
			ans.push_back(k);
	}
	cout << ans.size() << "\n";
	for(int i : ans)
		cout << i << " ";
	cout << "\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr); 
	int Cases;
	cin >> Cases;
	while(Cases--){
		cin >> n >> m;
		for(int i = 1; i <= n; i++)
			cin >> a[i];
		for(int i = 1; i <= m; i++)
			cin >> b[i];
		sort(a + 1, a + n + 1);
		sort(b + 1, b + m + 1);
		work();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3656kb

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
-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 2)