QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244238 | #7678. The Game | ucup-team2432# | RE | 0ms | 3816kb | C++20 | 1.9kb | 2023-11-08 22:09:20 | 2023-11-08 22:09:21 |
Judging History
answer
#include<bits/stdc++.h>
using LL = long long;
const LL inf = 1e9;
const LL P = 998244353;
void solve() {
int n,m;std::cin >> n >> m;
std::vector<int> a(n),b(m);
std::priority_queue<int,std::vector<int>,std::greater<>> q1,q2;
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
for (int i = 0; i < m; ++i) {
std::cin >> b[i];
}
LL need = 0;
for (int i = n-1, j = m-1; j >= 0; --j, --i) {
if (a[i] > b[j]) { std::cout << "-1\n";return; }
else need += b[j] - a[i];
q1.emplace(a[i]);
}
for (int i = n-m-1; i >= 0; --i) {
q2.emplace(a[i]);
}
if (need > n-m) { std::cout << "-1\n";return; }
std::vector<int> res;
// std::cout << "size:" << q1.size() << " " << q2.size() << '\n';
for (int i = 0; i < n-m-need; ++i) {
auto p = q2.top();q2.pop();
res.emplace_back(p);
p ++;
if (p > q1.top()) {
need -= p - q1.top();
q1.emplace(p),q2.emplace(q1.top());q1.pop();
if (q1.top() > b[0]) { std::cout << "-1\n";return; }
q2.pop();
} else {
q2.emplace(p),q2.pop();
}
}
int pointer = 0;
while (!q1.empty()) {
auto p = q1.top();q1.pop();
if (p == b[pointer]) pointer ++;
else if (pointer == m || p > b[pointer]){
std::cout << "-1\n";return;
} else {
res.emplace_back(p);
p ++;
if (q2.empty()) { std::cout << "-1\n";return; }
q2.pop();
q1.emplace(p);
}
}
if (!q2.empty() || res.size() != n-m) { std::cout << "-1\n";return; }
std::cout << res.size() << '\n';
for (auto x : res) {
std::cout << x << " ";
}
std::cout << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
// clock_t st = clock();
// std::cout << std::fixed << std::setprecision(12);
// freopen("test.in", "r", stdin);
// freopen("test.out", "w", stdout);
int T = 1;
std::cin >> T;
while (T --) {
solve();
}
// std::cout << (double)(clock()-st)/CLOCKS_PER_SEC;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
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
Runtime Error
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...