QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466889#7678. The Gamele6666WA 0ms5820kbC++142.3kb2024-07-08 11:39:582024-07-08 11:39:59

Judging History

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

  • [2024-07-08 11:39:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5820kb
  • [2024-07-08 11:39:58]
  • 提交

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;
	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) {
			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: 3784kb

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: 5820kb

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

result:

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