QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672825 | #8549. The Game | SCAU_xyjkanade | WA | 1ms | 3612kb | C++20 | 2.7kb | 2024-10-24 19:21:27 | 2024-10-24 19:21:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n,m;
int T;
int a[N];
int b[N];
bool cmp(int x,int y)
{
return x > y;
}
multiset <int> st;
vector <int> v;
void init()
{
while(!st.empty())st.erase(st.begin());
while(!v.empty())v.pop_back();
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> T;
while(T--)
{
init();
cin >> n >> m;
for(int i = 1;i <= n;i++)
cin >> a[i];
for(int i = 1;i <= m;i++)
cin >> b[i];
sort(a + 1,a + n + 1,cmp);
sort(b + 1,b + m + 1,cmp);
if(n < m){cout << -1 << '\n';continue;}
int flag = 1;
int sum = 0;
for(int i = 1;i <= m;i++)
{
if(a[i] > b[i]){cout << -1 << '\n';flag = 0;break;}
else{sum += b[i] - a[i];}
}
if(!flag){cout << -1 << '\n';continue;}
//st.clear();v.clear();
for(int i = 1;i <= n;i++)
st.insert(a[i]);
int ed = a[m];
int ans =0;
if(st.size() < m + sum)
{
cout << -1 << endl;
continue;
}
while(st.size() > m + sum)
{
set <int>::iterator it = st.begin();
if(*it >= ed){break;}
else{
st.erase(it);
int val = *it;
v.push_back(val);
val ++;
st.insert(val);
st.erase(st.begin());
ans++;
}
}
for(int i = 1;i <= m;i++)
{
while(*st.rbegin() < b[i])
{
int val = *st.rbegin();
set <int>::iterator it = st.find(val);
v.push_back(val);
val++;
ans++;
st.erase(it);
st.insert(val);
st.erase(st.begin());
}
if(*st.rbegin() == b[i])
{
int tt = *st.rbegin();
set <int>::iterator it = st.find(tt);
st.erase(it);
}
else{flag = 0;break;}
}
if(!flag){cout << -1 << '\n';continue;}
while(!st.empty())
{
set <int>::iterator it = st.begin();
int val = *it;
if(val == b[m]){flag = 0;break;}
ans++;
v.push_back(val);
val++;
st.erase(it);
st.insert(val);
st.erase(st.begin());
}
if(!flag){cout << -1<< '\n';continue;}
cout <<ans << '\n';
int len = v.size();
for(int i = 0;i < len;i++)
cout << v[i] << " ";
cout << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3612kb
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 -1 -1 -1
result:
wrong answer 1st words differ - expected: 'Qingyu', found: '-1'