QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#254911#7678. The GamezGoofyWA 11ms3756kbC++231.7kb2023-11-18 14:13:202023-11-18 14:13:22

Judging History

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

  • [2023-11-18 14:13:22]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3756kb
  • [2023-11-18 14:13:20]
  • 提交

answer


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




void solve() {
	int n, m;
	cin >> n >> m;
	vector<int>a(n + 1);
	vector<int>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());
	int res = 0;
	for (int i = 1; i <= m; i++) {
		if (b[i] < a[i + n - m]) {
			cout << "-1" << endl;
			return;
		}
		if (b[i] > a[i + n - m]) {
			res += b[i] - a[i + n - m];
		}
	}
	priority_queue<int, vector<int>, greater<int>>q1, q2;
	for (int i = 1; i <= n - m; i++) {
		q1.push(a[i]);
	}
	for (int i = n - m + 1; i <= n; i++) {
		q2.push(a[i]);
	}
	vector<int>ans;
	while(q1.size() > res) {
        int now = q1.top();q1.pop();
        ans.push_back(now);
        if(now + 1 > q2.top()) {
            res--;
            if(res < 0) {
                cout << -1 << endl;
                return;
            }
            q1.push(q2.top());
            q2.pop();
            q2.push(now + 1);
            q1.pop();
        } else {
            q1.push(now + 1);
            q1.pop();
        }
    }
    int idx = 1;
    while(q2.size()) {
        int now = q2.top();
        if(now == b[idx]) {
            q2.pop();
            idx++;
        } else if(now > b[idx]) {
            cout << -1 << endl;
            return;
        } else {
            q2.pop();
            ans.push_back(now);
            q2.push(now + 1);
        }
    }
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return;
}


signed main() {
	ios::sync_with_stdio(false);
	int tt = 1;
	cin >> tt;
	while (tt--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 11ms
memory: 3568kb

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 
2
1 2 
3
1 2 3 
4
1 2 3 4 
5
1 2 3 4 5 
2
1 1 
3
1 1 2 
4
1 1 2 3 
5
1 1 2 3 4 
6
1 1 2 3 4 5 
4
1 1 2 2 
5
1 1 2 2 3 
6
1 1 2 2 3 4 
7
1 1 2 2 3 4 5 
6
1 1 2 2 3 3 
7
1 1 2 2 3 3 4 
8
1 1 2 2 3 3 4 5 
8
1 1 2 2 3 3 4 4 
9
1 1 2 2 3 3 4 4 5 
10
1 1 2 2 3 3 4 4 5 5 
3
1 1 1 
4
1 1 1 2 
5
1 1 ...

result:

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