QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549908#7678. The Gameccsurzw#WA 0ms3516kbC++201.4kb2024-09-06 23:19:182024-09-06 23:19:18

Judging History

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

  • [2024-09-06 23:19:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3516kb
  • [2024-09-06 23:19:18]
  • 提交

answer

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

#define ll long long
#define endl "\n"
const ll mod = 1e9 + 7;
const int N = 5e5 + 5;
const int inf = 0x3f3f3f3f;

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int>a(n + 1), b(m + 1);
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int j = 1; j <= m; j++)cin >> b[j];
	sort(a.begin() + 1, a.end());
	sort(b.begin() + 1, b.end());
	ll sum = 0;
	for (int i = n, j = m; j >= 1; j--, i--) {
		if (a[i] > b[j]) {
			cout << -1 << endl;
			return;
		}
		sum += b[j] - a[i];
	}
	ll s = 0;
	int dis = n - m;
	if (sum > dis) {
		cout << -1 << endl;
		return;
	}

	s = dis - sum;
	multiset<int>st;
	for (int i = 1; i <= dis; i++)st.insert(a[i]);
	vector<int>ans;
	int ma = 0;
	while (s-- && !st.empty()) {
		int u = *st.begin();
		st.erase(st.begin());
		ans.push_back(u);
		u += 1;
		ma = max(ma, u);
		st.insert(u);
		st.erase(st.begin());
	}
	if (ma > b[1]) {
		cout << -1 << endl;
		return;
	}
	for (int i = dis + 1; i <= n; i++) {
		int len = b[i - dis] - a[i];
		while (len--)
			ans.push_back(a[i]++);
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++)cout << ans[i] << ' ';
	cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int t = 1;
	cin >> t;
	for (int i = 1; i <= t; i++)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3516kb

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

result:

wrong answer Wrong answer, erase a number that does not exist (test case 6)