QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#543266#7678. The Gamerxzfn639WA 2ms5860kbC++231.8kb2024-09-01 15:26:552024-09-01 15:26:56

Judging History

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

  • [2024-09-01 15:26:56]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5860kb
  • [2024-09-01 15:26:55]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long
#define pii make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
const ll inf = 1145141919810;
using namespace std;
inline ll read() {
	ll x=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9') {
		if (c=='-')  f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
inline void print(ll x) {
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + '0');
	return ;
}
inline void pprint(ll x) {
	print(x);
	puts("");
}
const int N = 4e5 + 7;
ll a[N], b[N];
bool cmp(ll x, ll y){
	return x > y;
}
void slv() {
	int n = read(), m = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 1, m) b[i] = read();
	sort(a + 1, a + 1 + n, cmp);
	sort(b + 1, b + 1 + m, cmp);
	if(n < m){
		puts("-1");
		return ;
	}
	vector<int> q, qq;
	ll rst = n - m;
	rep(i, 1, m){
		if(a[i] > b[i]){
			puts("-1");
			return ;
		}
		if(b[i] - a[i] <= rst){
			rep(j, a[i], b[i] - 1){
				qq.pb(j);
			}
			rst -= b[i] - a[i];
		}else{
			puts("-1");
			return ;
		}
	}

	priority_queue<ll> _q;
	for(int i = n; i >= 1 && rst > 0; rst--, i--){
		if(a[i] >= b[m]){
			puts("-1");
			return ;
		}
		_q.push(-a[i]);
	}

	while(_q.size()){
		ll x = -_q.top();
		if(x >= b[m]) {
			puts("-1");
			return ;
		}
        q.push_back(x);
		_q.pop();
		x++;
		_q.push(-x);
		_q.pop();
	}

    for (auto i: qq) q.push_back(i);

	pprint(q.size());

	for(auto x:q){
		print(x); putchar(' ');
	}
	puts("");
}
signed main() {
	int T = read();
	while(T--) {
		slv();
	}
	return 0;
}

/*
3
6 3
1 1 1 2 2 4
2 3 4

6 3
1 1 3 3 3 5
3 4 5

4 3
2 2 3 3
2 3 4
*/

詳細信息

Test #1:

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

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

result:

ok ok (6 test cases)

Test #2:

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

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: 1ms
memory: 5576kb

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
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
2
3 4 
-1
-1
-1
2
1 1 
2
3 1 
-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: 5660kb

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

result:

ok ok (2640 test cases)

Test #5:

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

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

result:

ok ok (14112 test cases)

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 5656kb

input:

5292
5 2
1 1 1 1 1
1 1
5 2
1 1 1 1 1
1 2
5 2
1 1 1 1 1
1 3
5 2
1 1 1 1 1
1 4
5 2
1 1 1 1 1
1 5
5 2
1 1 1 1 1
1 6
5 2
1 1 1 1 1
2 2
5 2
1 1 1 1 1
2 3
5 2
1 1 1 1 1
2 4
5 2
1 1 1 1 1
2 5
5 2
1 1 1 1 1
2 6
5 2
1 1 1 1 1
3 3
5 2
1 1 1 1 1
3 4
5 2
1 1 1 1 1
3 5
5 2
1 1 1 1 1
3 6
5 2
1 1 1 1 1
4 4
5 2
1 1...

output:

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

result:

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