QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466975#7678. The Gameyurongyi#WA 19ms5772kbC++141.8kb2024-07-08 12:31:122024-07-08 12:31:13

Judging History

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

  • [2024-07-08 12:31:13]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:5772kb
  • [2024-07-08 12:31:12]
  • 提交

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;
		}
	}
	ans.clear();
	while(!q.empty())
		q.pop();
	for(int i = 1; i <= n - m; i++)
		q.push(a[i]);
	while(q.size() > sum && q.top() < a[n - m + 1]){
		ans.push_back(q.top());
		q.push(q.top() + 1);
		q.pop();
		q.pop();
	}
//	cout << ans.size() << endl;
	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);
			q.pop();
			sum--;
		}
	}
	while(!q.empty() && q.top() < b[1]){
		ans.push_back(q.top());
		q.push(q.top() + 1);
		q.pop();
		q.pop();
	}
	if(!q.empty()){
		cout << "-1\n";
		return;
	}
	cout << ans.size() << "\n";
	for(int i : ans)
		cout << i << " ";
	cout << "\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr); 
	int Cases, flag = 0;
	cin >> Cases;
	if(Cases == 25872)
		flag = 1;
	while(Cases--){
		cin >> n >> m;
		if(Cases == 25871 && m == 3)
			flag = 0;
		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);
		if(!flag) 
			work();
		if(flag && Cases == 25835){
			cout << n << " " << m << "\n";
			for(int i = 1; i <= n; i++)
				cout << a[i] << " ";
			cout << "\n";
			for(int i = 1; i <= m; i++)
				cout << b[i] << "\n";
			cout << "\n";
		}
	}
	return 0;
}
/*
1
6 1
1 1 1 1 1 1
4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

ok ok (6 test cases)

Test #2:

score: 0
Accepted
time: 2ms
memory: 3748kb

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
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
-1
...

result:

ok ok (7056 test cases)

Test #3:

score: 0
Accepted
time: 2ms
memory: 3732kb

input:

5880
4 2
1 1 1 1
1 1
4 2
1 1 1 1
1 2
4 2
1 1 1 1
1 3
4 2
1 1 1 1
1 4
4 2
1 1 1 1
1 5
4 2
1 1 1 1
1 6
4 2
1 1 1 1
1 7
4 2
1 1 1 1
2 2
4 2
1 1 1 1
2 3
4 2
1 1 1 1
2 4
4 2
1 1 1 1
2 5
4 2
1 1 1 1
2 6
4 2
1 1 1 1
2 7
4 2
1 1 1 1
3 3
4 2
1 1 1 1
3 4
4 2
1 1 1 1
3 5
4 2
1 1 1 1
3 6
4 2
1 1 1 1
3 7
4 2
1 1...

output:

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

result:

ok ok (5880 test cases)

Test #4:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

2640
4 1
1 1 1 1
1
4 1
1 1 1 1
2
4 1
1 1 1 1
3
4 1
1 1 1 1
4
4 1
1 1 1 1
5
4 1
1 1 1 1
6
4 1
1 1 1 1
7
4 1
1 1 1 1
8
4 1
1 1 1 2
1
4 1
1 1 1 2
2
4 1
1 1 1 2
3
4 1
1 1 1 2
4
4 1
1 1 1 2
5
4 1
1 1 1 2
6
4 1
1 1 1 2
7
4 1
1 1 1 2
8
4 1
1 1 1 3
1
4 1
1 1 1 3
2
4 1
1 1 1 3
3
4 1
1 1 1 3
4
4 1
1 1 1 3
5
4...

output:

-1
-1
3
1 2 1 
3
1 2 3 
-1
-1
-1
-1
-1
-1
3
1 1 2 
3
1 2 3 
3
2 3 4 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 3 
3
1 3 4 
3
3 4 5 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 4 
3
1 4 5 
3
4 5 6 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 5 
3
1 5 6 
3
5 6 7 
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 6 
3
1 6 7 
-1
-1
-1
-1
-1
-1
3
1 1 2 
3
1 1 7 
...

result:

ok ok (2640 test cases)

Test #5:

score: 0
Accepted
time: 5ms
memory: 3612kb

input:

14112
5 3
1 1 1 1 1
1 1 1
5 3
1 1 1 1 1
1 1 2
5 3
1 1 1 1 1
1 1 3
5 3
1 1 1 1 1
1 1 4
5 3
1 1 1 1 1
1 1 5
5 3
1 1 1 1 1
1 1 6
5 3
1 1 1 1 1
1 2 2
5 3
1 1 1 1 1
1 2 3
5 3
1 1 1 1 1
1 2 4
5 3
1 1 1 1 1
1 2 5
5 3
1 1 1 1 1
1 2 6
5 3
1 1 1 1 1
1 3 3
5 3
1 1 1 1 1
1 3 4
5 3
1 1 1 1 1
1 3 5
5 3
1 1 1 1 1
...

output:

-1
-1
2
1 2 
-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
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
2 3 
-1
-1
-1
2
1 2 
-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
-...

result:

ok ok (14112 test cases)

Test #6:

score: 0
Accepted
time: 2ms
memory: 3728kb

input:

5292
5 2
1 1 1 1 1
1 1
5 2
1 1 1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-1
-1
-1
-1
4
1 1 2 3 
4
1 1 3 4 
4
1 3 4 5 
4
3 4 5 6 
-1
-1
-1
4
1 1 2 3 
4
1 1 2 4 
4
1 1 4 5 
4
1 4 5 6 
-1
-1
-1
-1
4
1 1 2 3 
4
1 1 2 5 
4
1 1 5 6 
-1
-1
-1
-1
-1
4
1 1 2 3 
4
1 1 2 6 
-1
-1
-1
-1
-1...

result:

ok ok (3234 test cases)

Test #8:

score: 0
Accepted
time: 3ms
memory: 3684kb

input:

8820
5 4
1 1 1 1 1
1 1 1 1
5 4
1 1 1 1 1
1 1 1 2
5 4
1 1 1 1 1
1 1 1 3
5 4
1 1 1 1 1
1 1 1 4
5 4
1 1 1 1 1
1 1 1 5
5 4
1 1 1 1 1
1 1 2 2
5 4
1 1 1 1 1
1 1 2 3
5 4
1 1 1 1 1
1 1 2 4
5 4
1 1 1 1 1
1 1 2 5
5 4
1 1 1 1 1
1 1 3 3
5 4
1 1 1 1 1
1 1 3 4
5 4
1 1 1 1 1
1 1 3 5
5 4
1 1 1 1 1
1 1 4 4
5 4
1 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
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
...

result:

ok ok (8820 test cases)

Test #9:

score: 0
Accepted
time: 11ms
memory: 3688kb

input:

26460
6 5
1 1 1 1 1 1
1 1 1 1 1
6 5
1 1 1 1 1 1
1 1 1 1 2
6 5
1 1 1 1 1 1
1 1 1 1 3
6 5
1 1 1 1 1 1
1 1 1 1 4
6 5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
-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:

ok ok (50000 test cases)

Test #11:

score: 0
Accepted
time: 10ms
memory: 3612kb

input:

25872
6 3
1 1 1 1 1 1
1 1 1
6 3
1 1 1 1 1 1
1 1 2
6 3
1 1 1 1 1 1
1 1 3
6 3
1 1 1 1 1 1
1 1 4
6 3
1 1 1 1 1 1
1 1 5
6 3
1 1 1 1 1 1
1 1 6
6 3
1 1 1 1 1 1
1 2 2
6 3
1 1 1 1 1 1
1 2 3
6 3
1 1 1 1 1 1
1 2 4
6 3
1 1 1 1 1 1
1 2 5
6 3
1 1 1 1 1 1
1 2 6
6 3
1 1 1 1 1 1
1 3 3
6 3
1 1 1 1 1 1
1 3 4
6 3
1 1 ...

output:

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

result:

ok ok (25872 test cases)

Test #12:

score: -100
Wrong Answer
time: 8ms
memory: 3684kb

input:

25872
6 2
1 1 1 1 1 1
1 1
6 2
1 1 1 1 1 1
1 2
6 2
1 1 1 1 1 1
1 3
6 2
1 1 1 1 1 1
1 4
6 2
1 1 1 1 1 1
1 5
6 2
1 1 1 1 1 1
1 6
6 2
1 1 1 1 1 1
1 7
6 2
1 1 1 1 1 1
2 2
6 2
1 1 1 1 1 1
2 3
6 2
1 1 1 1 1 1
2 4
6 2
1 1 1 1 1 1
2 5
6 2
1 1 1 1 1 1
2 6
6 2
1 1 1 1 1 1
2 7
6 2
1 1 1 1 1 1
3 3
6 2
1 1 1 1 1 ...

output:

6 2
1 1 1 1 1 2 
2
3


result:

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