/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 328.0 KiB
#3 Accepted 22ms 796.0 KiB
#4 Accepted 21ms 560.0 KiB
#5 Accepted 27ms 764.0 KiB
#6 Accepted 25ms 768.0 KiB
#7 Accepted 51ms 2.242 MiB
#8 Accepted 72ms 3.52 MiB
#9 Accepted 71ms 3.562 MiB
#10 Accepted 46ms 3.77 MiB
#11 Accepted 9ms 580.0 KiB
#12 Accepted 32ms 488.0 KiB

Code

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(auto &i: a) cin >> i;
    for(auto &i: b) cin >> i;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    // for(int i = 0; i < n; i++) cout << a[i] << " \n"[i + 1 == n];
    // for(int i = 0; i < n; i++) cout << b[i] << " \n"[i + 1 == n];

    auto check = [&](auto &v1, auto &v2) -> bool {
        vector<int> A(n), B(n);
        int j = 2;
        for(int i = 1; i < n - 1; i += 2) A[i] = v1[j++];
        for(int i = 2; i < n - 1; i += 2) A[i] = v1[j++];

        j = 0;
        for(int i = 0; i < n; i += 2) B[i] = v2[j++];
        for(int i = 1; i < n; i += 2) B[i] = v2[j++];

        for(int i = 1; i < n - 1; i++) {
            if(A[i] > B[i - 1] && A[i] > B[i + 1]) continue;
            return 0;
        }
        return 1;
    };
    
    if(check(a, b) or check(b, a)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1193 C. Roy and Peak Array
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-11 14:46:19
Judged At
2025-06-11 14:46:19
Judged By
Score
100
Total Time
72ms
Peak Memory
3.77 MiB