QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#681001 | #7678. The Game | QFshengxiu | TL | 3ms | 7656kb | C++23 | 2.2kb | 2024-10-27 00:06:42 | 2024-10-27 00:06:42 |
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;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= m; i++)
{
cin >> b[i];
}
if (m > n)
{
cout << -1 << endl;
return;
}
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--;
}
int shiji = n - m, cha = shiji - need;
if (cha < 0)
{
cout << -1 << endl;
return;
}
multiset<int> st, sc;
for (int i = n; i >= n - m + 1; i--)
st.insert(a[i]);
for (int i = 1; i <= n; i++)
sc.insert(a[i]);
while (cha > 0 && !sc.empty())
{
auto u = *sc.begin();
sc.erase(sc.begin());
sc.insert(u + 1);
ans.push_back(u);
if (u + 1 > *st.begin())
{
st.erase(st.begin());
need--;
if (need < 0)
{
cout << -1 << endl;
return;
}
st.insert(u + 1);
}
else
cha--;
sc.erase(sc.begin());
}
// print(sc);
l = n - m + 1;
int r = 1;
while (!st.empty())
{
auto u = *st.begin();
st.erase(st.begin());
if (u == b[r])
{
r++;
continue;
}
ans.push_back(u);
st.insert(u + 1);
sc.erase(sc.begin());
sc.insert(u + 1);
}
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();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7656kb
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: 0
Accepted
time: 3ms
memory: 7580kb
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 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 -1 ...
result:
ok ok (7056 test cases)
Test #3:
score: -100
Time Limit Exceeded
input:
5880 4 2 1 1 1 1 1 1 4 2 1 1 1 1 1 2 4 2 1 1 1 1 1 3 4 2 1 1 1 1 1 4 4 2 1 1 1 1 1 5 4 2 1 1 1 1 1 6 4 2 1 1 1 1 1 7 4 2 1 1 1 1 2 2 4 2 1 1 1 1 2 3 4 2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