QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#680901 | #8549. The Game | QFshengxiu | WA | 0ms | 7676kb | C++23 | 2.4kb | 2024-10-26 23:23:23 | 2024-10-26 23:23:24 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 4e5;
int a[N], b[N], c[N];
const int inf = 1e18;
void print(multiset<int> st)
{
for (auto c : st)
{
cout << c << " ";
}
cout << endl;
}
void solve()
{
int n, m;
cin >> n >> m;
int sum1 = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum1 += a[i];
}
int sum = 0;
for (int i = 1; i <= m; i++)
{
cin >> b[i];
sum += b[i];
}
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + m);
int l = m, need = 0;
vector<int> ans;
for (int i = n; i >= n - m + 1; i--)
{
if (b[l] < a[i])
{
cout << -1 << endl;
return;
}
need += b[l] - a[i];
l--;
}
if (n == m)
{
if (need != 0)
cout << -1 << endl;
else
cout << 0 << endl
<< endl;
return;
}
int shiji = n - m;
int cha = shiji - need;
multiset<int> st;
int lx = a[n - m + 1], rx = a[n - m + 2];
for (int i = 1; i <= n; i++)
{
st.insert(a[i]);
}
while (cha > 0 && !st.empty())
{
// print(st);
// cout << cha << " " << lx << endl;
auto x = *st.begin();
st.erase(st.begin());
ans.push_back(x);
st.insert(x + 1);
if (lx < x + 1)
{
if (m > 1 && rx <= x + 1)
{
lx = rx;
rx = x + 1;
}
else
{
lx = x + 1;
}
}
else
cha--;
st.erase(st.begin());
}
l = 0;
for (auto v : st)
{
c[++l] = v;
}
n = l;
l = n - m + 1;
int r = 1;
int cx = 1;
while (l <= n)
{
while (cx < l && c[l] != b[r])
{
ans.push_back(c[l]);
c[l]++;
cx++;
}
if ((cx == l && c[l] != b[r]) || cx > l)
{
cout << -1 << endl;
return;
}
l++, r++;
}
cout << ans.size() << endl;
for (auto c : ans)
{
cout << c << ' ';
}
cout << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0);
int T = 1;
cin >> T;
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7676kb
input:
3 3 1 1 4 5 1 4 2 1 2 3 4 4 1 2 2 3 2 1 1 4
output:
-1 -1 -1
result:
wrong answer 1st words differ - expected: 'Qingyu', found: '-1'