QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673113 | #5260. The Game | SCAU_xyjkanade | WA | 0ms | 3632kb | C++20 | 2.7kb | 2024-10-24 20:37:24 | 2024-10-24 20:37:27 |
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 << endl;continue;}
int flag = 1;
int sum = 0;
for(int i = 1;i <= m;i++)
{
if(a[i] > b[i]){flag = 0;break;}
else{sum += b[i] - a[i];}
}
if(!flag){cout << -1 << endl;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 << endl;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<< endl;continue;}
cout <<ans << endl;
int len = v.size();
for(int i = 0;i < len;i++)
cout << v[i] << " ";
if(ans)cout << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
output:
-1 -1
result:
wrong answer 1st lines differ - expected: '1 2 3 4 5 6 7 8 9 10 11 12 13 ...9 90 91 92 93 94 95 96 97 98 99', found: '-1'