QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647039#7678. The Gameucup-team2526WA 3ms3632kbC++202.1kb2024-10-17 11:12:402024-10-17 11:12:40

Judging History

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

  • [2024-10-17 11:12:40]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3632kb
  • [2024-10-17 11:12:40]
  • 提交

answer

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

#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)

void err() {
	std::cout << std::endl;
}

template<class T, class... Ts>
void err(T arg, Ts &... args) {
	std::cout << fixed << setprecision(10) << arg << ' ';
	err(args...);
}

void GENSHEN_START() {
	int n,m;cin >> n >> m;
	vector <int> a(n + 5),b(m + 5);
	int cnt1 = 0;
	for (int i = 1;i <= n;i++) cin >> a[i];
	for (int i = 1;i <= m;i++) cin >> b[i];
	sort(a.begin() + 1,a.begin() + 1 + n);
	sort(b.begin() + 1,b.begin() + 1 + m);
	for (int i = 1;i <= m;i++) cnt1 += (b[i] == b[1]);
	int lst = -1,ok = 0;
	for (int i = 1;i <= n;i++) {
		if (a[i] < b[1]) lst = i;
	}
	vector<int>ans;
	int l = 1;
	int val = -1,mod = 0,cnt = 0;
	for (int i = lst;i >= 1;i--) {
		int x = a[i];
		if (b[1] - x <= i - l) {
			cnt++;
			while (x != b[1]) {
				ans.push_back(x);
				x++;
				l++;
			}
		}
		else {
			val = x;
			mod = i - l + 1;
			break;
		}
	}
	vector<int>c;
	int cnt2 = 0;
	while (cnt) {
		c.push_back(b[1]);
		cnt--;
		cnt2++;
	}
	for (int i = 1;i <= n;i++) {
		if (a[i] >= b[1]) c.push_back(a[i]);
		cnt2 += (a[i] == b[1]);
	}
	//for (auto i : c) dbg(i);
	//dbg(mod);
	int len = c.size();
	if (cnt2 < cnt1) {
		cout << "-1" << '\n';
		return ;
	}
	if (len - (cnt2 - cnt1) > m) {
		cout << "-1" << '\n';
		return ;
	}
	int all = len - m,sum = 0;
	for (int i = len - m;i < len;i++) {
		if (c[i] > b[i - len + m + 1]) {
			cout << "-1" << '\n';
			return ;
		}
		sum += b[i - len + m + 1] - c[i];
	}
	if (sum >= all && sum <= all + mod) {
		for (int i = 1;i <= mod - (sum - all);i++) {
			ans.push_back(val);
			val++;
		}
		for (int i = len - m;i < len;i++) {
			while (c[i] < b[i - len + m + 1]) {
				ans.push_back(c[i]);
				c[i]++;
			}
		}
		cout << ans.size() << '\n';
		for (auto i : ans) cout << i << ' ';
		cout << '\n';
	}
	else {
		cout << "-1" << '\n';
	}
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int T = 1;
	cin >> T;
	while (T--) GENSHEN_START();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

ok ok (6 test cases)

Test #2:

score: 0
Accepted
time: 3ms
memory: 3632kb

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

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

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