QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466890#7678. The Gamele6666WA 3ms3800kbC++142.3kb2024-07-08 11:40:492024-07-08 11:40:49

Judging History

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

  • [2024-07-08 11:40:49]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3800kb
  • [2024-07-08 11:40:49]
  • 提交

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); int cnt = 0, tmp = t;
	while (t--) {
		scanf("%d%d", &n, &m); cnt++;
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
		if (cnt == 31 && tmp == 5880) {
			printf("%d %d\n", n, m);
			for (int i = 1; i <= n; i++) printf("%d ", a[i]); printf("\n");
			for (int i = 1; i <= m; i++) printf("%d ", b[i]); printf("\n");
			return 0;
		}
		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


*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3ms
memory: 3784kb

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

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

result:

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