QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#466961 | #7685. Barkley II | yurongyi# | WA | 0ms | 3656kb | C++14 | 1.7kb | 2024-07-08 12:08:16 | 2024-07-08 12:08:16 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N = 3e5 + 10;
int n, m, a[N], b[N];
vector <int> ans;
priority_queue < int, vector <int>, greater <int> > q;
void work(){
int sum = 0;
for(int i = n - m + 1, j = 1; j <= m; i++, j++){
if(a[i] > b[j]){
cout << "-1\n";
return;
}
sum += b[j] - a[i];
// cout << sum << endl;
if(sum > n - m){
cout << "-1\n";
return;
}
}
ans.clear();
while(!q.empty())
q.pop();
for(int i = 1; i <= n - m; i++)
q.push(a[i]);
while(q.size() > sum && q.top() < a[n - m + 1]){
ans.push_back(q.top());
q.push(q.top() + 1);
q.pop();
q.pop();
}
cout << ans.size() << endl;
for(int i = n - m + 1, j = 1; j <= m; i++, j++){
for(int k = a[i]; k < b[j]; k++){
ans.push_back(k);
q.pop();
sum--;
}
}
while(!q.empty() && q.top() < b[1]){
ans.push_back(q.top());
q.push(q.top() + 1);
q.pop();
q.pop();
}
if(!q.empty()){
cout << "-1\n";
return;
}
cout << ans.size() << "\n";
for(int i : ans)
cout << i << " ";
cout << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Cases, flag = 0;
cin >> Cases;
if(Cases == 5880)
flag = 1;
while(Cases--){
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);
sort(b + 1, b + m + 1);
if(!flag)
work();
if(flag && Cases == 5502){
cout << n << " " << m << "\n";
for(int i = 1; i <= n; i++)
cout << a[i] << "\n";
for(int i = 1; i <= m; i++)
cout << b[i] << "\n";
}
}
return 0;
}
/*
1
6 1
1 1 1 1 1 1
4
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3656kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
-1 -1
result:
wrong answer 1st numbers differ - expected: '2', found: '-1'