QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#245642#7678. The GameUNos_mariconesWA 1ms3524kbC++202.2kb2023-11-10 08:38:302023-11-10 08:38:30

Judging History

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

  • [2023-11-10 08:38:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3524kb
  • [2023-11-10 08:38:30]
  • 提交

answer

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

#define ff   first
#define ss   second
#define pb   push_back

typedef long long  ll;
typedef pair<ll,ll>  pii;

const ll N = 4e5 + 10;
const ll mod = 1e9 + 7;
const ll oo = 1e18;


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifdef LOCAL
  freopen("input.txt","r",stdin);
  #endif // LOCAL

  ll t; cin >> t;
  while (t--) {

    ll n,m; cin >> n >> m;
    vector <ll> a(n), b(m);
    for (auto &e : a) cin >> e;
    for (auto &e : b) cin >> e;

    sort (a.begin(), a.end());
    sort (b.begin(), b.end());

    ll can = 1;
    if (m > n) can = 0;
    if (can == 0) {
      cout << -1 << '\n';
      continue;
    }

    ll sum = 0, fa = a[n - m], fb = b[0];
    vector <ll> ty2;

    for (ll i = n - 1, j = m - 1; j >= 0; --i, --j) {
      if (a[i] > b[j]) can = 0;
      else {
        if (sum + b[j] - a[i] > n - m) {
          can = 0;
          break;
        }
        for (ll k = b[j] - 1; k >= a[i]; --k) ty2.pb(k);
        sum += b[j] - a[i];
      }
    }
    reverse(ty2.begin(), ty2.end());

    if (can == 0) {
      cout << -1 << '\n';
      continue;
    }

    vector <ll> ans;
    multiset <ll> curr;
    for (auto &e : a) curr.insert(e);

    ll cput = 0, idx = 0;
    for (ll cf = fa; cf < fb; ++cf) {
      while (cput + sum < n - m) {
        ll be = *curr.begin();
        if (be == cf) break;
        ans.pb(be);
        cput++;
        curr.erase(curr.begin());
        curr.insert(be + 1);
        curr.erase(curr.begin());
      }

      if (cf < fb) {
        curr.erase(curr.lower_bound(ty2[idx]));
        curr.insert(ty2[idx] + 1);
        curr.erase(curr.begin());
        ans.pb(ty2[idx++]);
      }
    }
    while (idx < sum) {
      curr.erase(curr.lower_bound(ty2[idx]));
      curr.insert(ty2[idx] + 1);
      curr.erase(curr.begin());
      ans.pb(ty2[idx++]);
    }

    if (curr.size() > m) can = 0;

    if (can) {
      cout << n - m << '\n';
      assert(ans.size() == n - m && curr.size() == m);
      for (auto &e : ans) cout << e << ' ';
      cout << '\n';
    }
    else cout << -1 << '\n';

  }

  return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3524kb

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:

-1
-1
3
2 4 4 
5
1 1 1 2 3 
-1
-1

result:

wrong answer Jury has answer but participant has not (test case 1)