QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#647113 | #7678. The Game | ucup-team2526 | TL | 0ms | 3632kb | C++20 | 2.2kb | 2024-10-17 11:48:11 | 2024-10-17 11:48:12 |
Judging History
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...);
}
int ttt;
void GENSHEN_START() {
ttt++;
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) {
if (ttt == 206) while (1);
cout << "-1" << '\n';
return ;
}
if (len - (cnt2 - cnt1) > m) {
// if (ttt == 206) while (1);
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]) {
//if (ttt == 206) while (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 {
//if (ttt == 206) while (1);
cout << "-1" << '\n';
}
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) GENSHEN_START();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
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: -100
Time Limit Exceeded
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...