QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#318076 | #7678. The Game | Decade | WA | 12ms | 7920kb | C++14 | 2.7kb | 2024-01-30 14:25:00 | 2024-01-30 14:25:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef long long ull;
typedef unsigned long long uull;
typedef pair<int, int> PII;
mt19937 rnd1(random_device{}());
mt19937_64 rnd2(random_device{}());
uniform_int_distribution<int> dist1(0,2e18); //定义dist1为0——100的随机整数
uniform_real_distribution<double> dist2(-10,10); //定义dist2为-10——10的随机浮点数
//#define mp make_pair
//fflush(stdout);
inline void print(__int128 x){//输出模板
if(x<0){
putchar('-');
x=-x;
}
if(x>9) print(x/10);
putchar(x%10+'0');
}
inline int read()
{
int X = 0;
bool flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
flag = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
X = (X << 1) + (X << 3) + ch - '0';
ch = getchar();
}
if (flag)
return X;
return ~(X - 1);
}
const ull mod = 1e9+7,INF = 2e18;
ull qpow(ull a, ull b)
{
ull res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int N = 300010,M = 400010;
int a[N],b[N],ans[N];
priority_queue<int,vector<int>,greater<int> > q;
void solve()
{
while(q.size()) q.pop();
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];
sort(a+1,a+1+n);
sort(b+1,b+1+m);
int s = 0,flag = 1,idx = 0;
for(int i=1;i<=m;i++)
if(b[i]>=a[n-m+i])
{
int t = b[i]-a[n-m+i];
s += t;
}
else
{
cout<<-1<<endl;
return;
}
int nd = n-m-s;
if(nd<0)
{
cout<<-1<<endl;
return;
}
for(int i=1;i<=nd;i++) q.push(a[i]);
int maxi = 0;
while(q.size())
{
int t = q.top();
ans[++idx] = t;
q.pop(),q.push(t+1);
maxi = max(maxi,t+1);
q.pop();
}
for(int i=1;i<=m;i++)
{
int t = b[i]-a[n-m+i];
for(int j=1;j<=t;j++) ans[++idx] = a[n-m+i],a[n-m+i]++;
}
if(maxi>b[1]) cout<<-1<<endl;
else
{
cout<<idx<<endl;
for(int i=1;i<=idx;i++) cout<<ans[i]<<' ';
cout<<endl;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin>>t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7684kb
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 2 1 2 3 2 1 1 -1
result:
ok ok (6 test cases)
Test #2:
score: 0
Accepted
time: 12ms
memory: 7920kb
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 -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 -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 -...
result:
ok ok (14112 test cases)
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 7760kb
input:
5292 5 2 1 1 1 1 1 1 1 5 2 1 1 1 1 1 1 2 5 2 1 1 1 1 1 1 3 5 2 1 1 1 1 1 1 4 5 2 1 1 1 1 1 1 5 5 2 1 1 1 1 1 1 6 5 2 1 1 1 1 1 2 2 5 2 1 1 1 1 1 2 3 5 2 1 1 1 1 1 2 4 5 2 1 1 1 1 1 2 5 5 2 1 1 1 1 1 2 6 5 2 1 1 1 1 1 3 3 5 2 1 1 1 1 1 3 4 5 2 1 1 1 1 1 3 5 5 2 1 1 1 1 1 3 6 5 2 1 1 1 1 1 4 4 5 2 1 1...
output:
-1 -1 -1 3 1 2 3 -1 -1 3 1 1 1 3 1 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 2 3 4 -1 -1 3 1 1 2 3 1 2 3 -1 -1 3 1 2 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 4 5 -1 -1 3 1 1 3 3 1 3 4 -1 3 1 1 2 3 1 2 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 1 1 4 3 1...
result:
wrong answer Jury has answer but participant has not (test case 134)