QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#254551 | #7678. The Game | sundage# | WA | 4ms | 3532kb | C++17 | 1.5kb | 2023-11-18 13:17:55 | 2023-11-18 13:17:56 |
Judging History
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);
map<int, int>mp;
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());
for (int i = 1; i <= n; i++) {
mp[a[i]] = i;
}
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];
}
}
if (res > n - m) {
cout << "-1" << endl;
return;
}
res = n - m - res;
vector<int>ans;
for (int i = 1; i <= n - m && res > 0; i++) {
if (res > 0) {
res--;
a[i]++;
ans.push_back(a[i] - 1);
if (mp[a[i] - 1] > i) {
if (mp[a[i] - 1] > n - m) {
res++;
}
mp[a[i]] = max(mp[a[i]], mp[a[i] - 1]);
swap(a[i], a[mp[a[i] - 1]]);
mp[a[i]]--;
}
}
}
if (a[1 + n - m] > b[1]) {
cout << "-1" << endl;
return;
}
for (int i = m; i >= 1; i--) {
if (a[i + n - m] < b[i]) {
for (; a[i + n - m] < b[i] ;) {
ans.push_back(a[i + n - m]);
a[i + n - m]++;
}
}
}
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: 3532kb
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: 4ms
memory: 3532kb
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 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...
result:
wrong answer Wrong answer, the final sequence does not equal to B (test case 1)