/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 25ms 532.0 KiB
#4 Accepted 24ms 584.0 KiB
#5 Accepted 37ms 792.0 KiB
#6 Accepted 37ms 764.0 KiB
#7 Accepted 66ms 2.82 MiB
#8 Accepted 41ms 5.02 MiB
#9 Accepted 40ms 5.02 MiB
#10 Accepted 43ms 3.52 MiB
#11 Accepted 10ms 572.0 KiB
#12 Accepted 25ms 584.0 KiB

Code

#include <bits/stdc++.h>

using namespace std;

bool check(vector<int> a, vector<int> b) {
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  int n = a.size();
  if (n < 3) return true;
  if (n == 3) {
    return a[0] > max(b[1], b[2]) || b[0] > max(a[1], b[2]);
  }
  int last = b.back(); b.pop_back();
  int cnt = (n - 1) / 2;
  for (int i = n - 3; i >= 0; --i, --cnt) {
    if (cnt == 0) {
      last = b.back(); b.pop_back();
      cnt = (n - 1) / 2;
    }
    if (last >= a[i]) return false;
    if (b.back() >= a[i]) return false;
    last = b.back();
    b.pop_back();
  }
  assert(cnt == 0 || cnt == 1);
  assert(b.empty());
  return true;
}

void solve(int cs) {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  cout << ((check(a, b) || check(b, a)) ? "Yes\n" : "No\n");
}

int32_t main() {
  cin.tie(0) -> sync_with_stdio(0);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1193 C. Roy and Peak Array
Contest
Brain Booster #10
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-13 17:44:44
Judged At
2025-06-13 17:44:44
Judged By
Score
100
Total Time
66ms
Peak Memory
5.02 MiB