QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303746 | #7678. The Game | Detach | WA | 0ms | 3532kb | C++17 | 3.7kb | 2024-01-12 22:35:58 | 2024-01-12 22:35:58 |
Judging History
answer
#include <bits/stdc++.h>
// #include <algorithm>
// #include <queue>
// #include <map>
// #include <iostream>
// #include <string>
// #include <set>
#define endl '\n'
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using i128 = __int128_t;
using ULL = unsigned long long;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7, N = 1e6 + 5;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
struct node
{
int val, idx;
bool operator<(const struct node & W) const
{
if(val != W.val) return val < W.val;
return idx > W.idx;
}
bool operator > (const struct node & W) const
{
if(val != W.val) return val > W.val;
return idx < W.idx;
}
}node;
void solve()
{
int n, m;
cin >> n >> m;
if(n < m)
{
cout << -1 << endl;
return;
}
vector<int> f(n - m), g(m), b(m);
multiset<int> S;
for(int i = 0; i < n - m; i ++ )
{
cin >> f[i];
S.insert(f[i]);
}
for(int i = 0; i < m; i ++ ) cin >> g[i];
for(int i = 0; i < m; i ++ ) cin >> b[i];
LL sum = 0;
int idx = -1;
for(int i = 0; i < m; i ++ )
{
if(g[i] > b[i])
{
cout << -1 << endl;
return;
}
if(idx == -1 and b[i] != g[i]) idx = i;
sum += b[i] - g[i];
}
if(sum > n - m)
{
cout << -1 << endl;
return;
}
priority_queue<struct node, vector<struct node>, greater<struct node> > q;
for(int i = 0; i < m; i ++ )
{
q.push({g[i], i});
}
// cout << sum << endl;
vector<int> ans;
int cnt = 0;
int num = S.size();
for(auto it = S.begin(); ; it = next(it))
{
if(cnt >= n - m - sum or it == S.end())
{
S.erase(prev(it));
break;
}
bool ok = true;
if(*it == b[0])
{
cout << -1 << endl;
return;
}
auto nxt = next(it);
if(nxt != S.end() and *nxt == *it)
{
if(*it + 1 > g[0])
{
ok = false;
if(q.empty())
{
cout << -1 << endl;
return;
}
auto [val, idx] = q.top();
q.pop();
ans.push_back(num + idx + 1);
g[idx] ++ ;
if(g[idx] < b[idx]) q.push({g[idx], idx});
cnt -- ;
}
else
{
S.erase(nxt);
S.insert(*it + 1);
}
}
if(ok) ans.push_back(1);
cnt ++ ;
if(it != S.begin())
{
S.erase(prev(it));
}
num -- ;
// for(auto j : S) cout << j << ' ';cout << endl;cout << *it << endl;
}
// cout << "----" << endl;// return;
int sz = S.size();
while(!S.empty())
{
if(q.empty())
{
cout << -1 << endl;
return;
}
auto [val, idx] = q.top();
q.pop();
ans.push_back(sz + idx + 1);
g[idx] ++ ;
if(g[idx] < b[idx]) q.push({g[idx], idx});
S.erase(S.begin());
sz -- ;
}
cout << n - m << endl;
for(auto it : ans) cout << it << ' ';
cout << endl;
// cout << "----" << endl;
}
int main()
{
// freopen("galactic.in", "r", stdin);
ios::sync_with_stdio(false), cin.tie(nullptr);
int T = 1;
cin >> T;
while(T -- )
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3532kb
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 2 -1 3 1 4 2 5 6 1 1 3 2 2 3 1 -1
result:
wrong answer Wrong answer, the final sequence does not equal to B (test case 1)