/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 328.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 50ms 576.0 KiB
#4 Accepted 51ms 788.0 KiB
#5 Accepted 64ms 560.0 KiB
#6 Accepted 55ms 540.0 KiB
#7 Accepted 109ms 1.277 MiB
#8 Accepted 122ms 2.074 MiB
#9 Accepted 122ms 2.027 MiB
#10 Accepted 165ms 2.07 MiB
#11 Accepted 21ms 540.0 KiB
#12 Accepted 44ms 540.0 KiB

Code

#include "bits/stdc++.h"
using namespace std;
#define k(n) begin(n), end(n)

void solve(){
  int n; cin >> n;
  vector<int> a(n), b(n);
  for (auto &e: a) cin >> e;
  for (auto &e: b) cin >> e;
  sort(k(a)), sort(k(b));
  
  int g1 = 1, g2 = 1;
  
  int p = n/2 - 1;
  if (n & 1) p++;

  for (int i = 0; i < p; i++){
    if (a[i + 2] <= b[i] || a[i + 2] <= b[i + 1]) g1 = 0;
    if (b[i + 2] <= a[i] || b[i + 2] <= a[i + 1]) g2 = 0;
  }
  for (int i = p; i < n - 2; i++){
    if (a[i + 2] <= b[i + 1] || a[i + 2] <= b[i + 2]) g1 = 0;
    if (b[i + 2] <= a[i + 1] || b[i + 2] <= a[i + 2]) g2 = 0;
  }
  
  cout << (g1 || g2 ? "Yes\n" : "No\n");
}

int main(){int t; cin >> t; while (t--) solve();}

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:17:03
Judged At
2025-06-13 17:17:03
Judged By
Score
100
Total Time
165ms
Peak Memory
2.074 MiB