QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#466881#7678. The Gamele6666WA 4ms5904kbC++142.0kb2024-07-08 11:34:222024-07-08 11:34:23

Judging History

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

  • [2024-07-08 11:34:23]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5904kb
  • [2024-07-08 11:34:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 3e5 + 5;
int t, n, m, a[MAXN], b[MAXN], ans[MAXN];

void check() {
	multiset<int> u, v;
	for (int i = 1; i <= n; i++) u.insert(a[i]);
	for (int i = 1; i <= m; i++) v.insert(b[i]);
	for (int i = 1; i <= n - m; i++) {
		u.erase(u.find(ans[i]));
		u.insert(ans[i] + 1);
		u.erase(u.begin());
	}
	assert(u == v);
}

bool sovle() {
	ll suma = 0, sumb = 0;
	for (int i = 1; i <= m; i++) {
		if (a[i] > b[i]) return false;
		suma += a[i], sumb += b[i];
	}
	if (sumb - suma > n - m) return false;
	multiset<int> s, v;
	for (int i = 1; i <= m; i++) v.insert(a[i]);
	for (int i = 1; i <= n; i++) s.insert(a[i]);
	int num = (n - m) - (sumb - suma);
	for (int i = 1; i <= n - m; i++) {
		if (num > 0) {
			int x = *s.begin(); s.erase(s.begin()), s.insert(x + 1), s.erase(s.begin());
			ans[i] = x;
			if (x < *v.begin()) num--;
			else v.insert(*v.begin() + 1), v.erase(v.begin());
		}
		else {
			for (int j = m; j >= 1; j--) a[j] = *v.begin(), v.erase(v.begin());
			for (int j = 1; j <= m; j++) {
				if (a[j] > b[j]) return false;
				for (int k = a[j]; k < b[j]; k++) ans[i++] = k;
			}
		}
	}
	if (num > 0) return false;
//	check();
	printf("%d\n", n - m);
	for (int i = 1; i <= n - m; i++) printf("%d ", ans[i]);
	printf("\n");
//	printf("1\n");
	return true;
}

int main() {
//	freopen("B.in", "r", stdin);
//	freopen("gcd.out", "w", stdout);
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
		sort(a + 1, a + 1 + n, [](int x, int y) { return x > y; });
		sort(b + 1, b + 1 + m, [](int x, int y) { return x > y; });
		if (!sovle()) printf("-1\n");
	}
	return 0;
}
/*

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

1000
20 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
5
20 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
4
5 5
1 2 3 4 5
5 4 2 1 3


*/

详细

Test #1:

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

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: 0
Accepted
time: 2ms
memory: 5848kb

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: -100
Wrong Answer
time: 4ms
memory: 5824kb

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

result:

wrong answer Wrong answer, the final sequence does not equal to B (test case 31)