QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#679827 | #7678. The Game | Displace_# | TL | 1ms | 5696kb | C++14 | 1.6kb | 2024-10-26 18:47:07 | 2024-10-26 18:47:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar()) f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
return (f)?(-x):x;
}
const int N=3e5+86;
int T,n,m,a[N],b[N],sm1,sm2,sm3;
int op1,op2,as[N],k=0;
priority_queue<int, vector<int>, greater<int> > s1,s2;
int main()
{
T=read();
while(T--)
{
while(s1.size()) s1.pop();
while(s2.size()) s2.pop();
sm1=sm2=sm3=0;k=0;
n=read();m=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=m;i++) b[i]=read(),sm2+=b[i];
sort(a+1,a+1+n);
sort(b+1,b+1+m);
for(int i=n-m+1;i<=n;i++) sm1+=a[i];
op2=sm2-sm1;
op1=(n-m)-op2;
if(op1<0||op2>(n-m)||a[n]>b[m])
{
cout<<"-1"<<endl;
continue;
}
for(int i=1;i<=n-m;i++) s1.push(a[i]);
for(int i=n-m+1;i<=n;i++) s2.push(a[i]);
int kb=1;
while(op1+op2>0)
{
// cout<<op1<<" "<<op2<<endl;
if(s1.empty()) break;
while(op1&&s1.size()&&s1.top()<s2.top())
{
int te=s1.top();
as[++k]=te;
s1.pop();
s1.push(te+1);
s1.pop();
op1--;
}
if(s2.empty()) break;
int te=s2.top();
while(te==b[kb]&&kb<=m)
{
s2.pop();
te=s2.top();
kb++;
}
if(kb>m||s2.empty()||s1.empty()||op1<0||op2<0) break;
if(op2)
{
s2.pop();
as[++k]=te;
s2.push(te+1);
s1.pop();
op2--;
}
}
if(op1||op2) cout<<"-1"<<endl;
else
{
cout<<n-m<<endl;
for(int i=1;i<=n-m;i++) cout<<as[i]<<" ";
cout<<endl;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5696kb
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: -100
Time Limit Exceeded
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 ...