QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#680904#7678. The GameQFshengxiuWA 8ms7676kbC++232.4kb2024-10-26 23:24:342024-10-26 23:24:38

Judging History

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

  • [2024-10-26 23:24:38]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:7676kb
  • [2024-10-26 23:24:34]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 4e5;
int a[N], b[N], c[N];
const int inf = 1e18;
void print(multiset<int> st)
{
    for (auto c : st)
    {
        cout << c << " ";
    }
    cout << endl;
}
void solve()
{
    int n, m;
    cin >> n >> m;
    int sum1 = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum1 += a[i];
    }
    int sum = 0;
    for (int i = 1; i <= m; i++)
    {
        cin >> b[i];
        sum += b[i];
    }
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + m);
    int l = m, need = 0;
    vector<int> ans;
    for (int i = n; i >= n - m + 1; i--)
    {
        if (b[l] < a[i])
        {
            cout << -1 << endl;
            return;
        }
        need += b[l] - a[i];
        l--;
    }

    if (n == m)
    {
        if (need != 0)
            cout << -1 << endl;
        else
            cout << 0 << endl
                 << endl;
        return;
    }
    int shiji = n - m;
    int cha = shiji - need;
    multiset<int> st;
    int lx = a[n - m + 1], rx = a[n - m + 2];
    for (int i = 1; i <= n; i++)
    {
        st.insert(a[i]);
    }
    while (cha > 0 && !st.empty())
    {
        // print(st);
        // cout << cha << " " << lx << endl;
        auto x = *st.begin();
        st.erase(st.begin());
        ans.push_back(x);
        st.insert(x + 1);
        if (lx < x + 1)
        {
            if (m > 1 && rx <= x + 1)
            {
                lx = rx;
                rx = x + 1;
            }
            else
            {
                lx = x + 1;
            }
        }
        else
            cha--;
        st.erase(st.begin());
    }
    l = 0;
    for (auto v : st)
    {
        c[++l] = v;
    }
    n = l;
    l = n - m + 1;
    int r = 1;
    int cx = 1;
    while (l <= n)
    {
        while (cx < l && c[l] != b[r])
        {
            ans.push_back(c[l]);
            c[l]++;
            cx++;
        }
        if ((cx == l && c[l] != b[r]) || cx > l)
        {
            cout << -1 << endl;
            return;
        }
        l++, r++;
    }
    cout << ans.size() << endl;
    for (auto c : ans)
    {
        cout << c << ' ';
    }
    cout << endl;
}
signed main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7676kb

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
Wrong Answer
time: 8ms
memory: 7636kb

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

result:

wrong answer Wrong answer, number of operation is not correct (test case 3)