QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#248982#7678. The GameCu_OH_2WA 3ms3864kbC++141.7kb2023-11-11 23:20:002023-11-11 23:20:01

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 23:20:01]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3864kb
  • [2023-11-11 23:20:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, m;

void solve()
{
    cin >> n >> m;
    multiset<int> ms1, ms2;
    for (int i = 1; i <= n; ++i)
    {
        int x;
        cin >> x;
        ms1.insert(x);
    }
    for (int i = 1; i <= m; ++i)
    {
        int x;
        cin >> x;
        ms2.insert(x);
    }
    vector<int> ans;
    ll need = 0;
    int mm = 2e9;
    while (ms2.size())
    {
        if (*ms2.rbegin() < *ms1.rbegin())
        {
            cout << "-1\n";
            return;
        }
        need += *ms2.rbegin() - *ms1.rbegin();
        mm = min(mm, *ms1.rbegin());
        for (int i = *ms2.rbegin() - 1; i >= *ms1.rbegin(); --i)
        {
            ans.push_back(i);
            if (ans.size() > n - m)
            {
                cout << "-1\n";
                return;
            }
        }
        ms2.erase(prev(ms2.end()));
        ms1.erase(prev(ms1.end()));
    }
    if (ms1.size() < need)
    {
        cout << "-1\n";
        return;
    }
    vector<int> v;
    while (ms1.size() > need)
    {
        int x = *ms1.begin();
        ms1.erase(ms1.begin());
        ms1.insert(x + 1);
        v.push_back(x);
        if (*ms1.begin() > mm)
        {
            cout << "-1\n";
            return;
        }
        ms1.erase(ms1.begin());
    }
    reverse(ans.begin(), ans.end());
    for (auto e : ans) v.push_back(e);
    cout << v.size() << '\n';
    for (auto e : v) cout << e << ' ';
    cout << '\n';
    return;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

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: 0
Accepted
time: 2ms
memory: 3568kb

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
...

result:

ok ok (7056 test cases)

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 3864kb

input:

5880
4 2
1 1 1 1
1 1
4 2
1 1 1 1
1 2
4 2
1 1 1 1
1 3
4 2
1 1 1 1
1 4
4 2
1 1 1 1
1 5
4 2
1 1 1 1
1 6
4 2
1 1 1 1
1 7
4 2
1 1 1 1
2 2
4 2
1 1 1 1
2 3
4 2
1 1 1 1
2 4
4 2
1 1 1 1
2 5
4 2
1 1 1 1
2 6
4 2
1 1 1 1
2 7
4 2
1 1 1 1
3 3
4 2
1 1 1 1
3 4
4 2
1 1 1 1
3 5
4 2
1 1 1 1
3 6
4 2
1 1 1 1
3 7
4 2
1 1...

output:

-1
2
1 1 
2
1 2 
-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
2
1 2 
2
2 3 
-1
-1
-1
2
1 1 
2
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
1 3 
2
3 4 
-1
-1
-1
2
1 1 
2
1 3 
-1
-1
-1
2
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer Wrong answer, the final sequence does not equal to B (test case 2)