/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 544.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Wrong Answer 21ms 540.0 KiB
#4 Wrong Answer 20ms 788.0 KiB

Code

/*
 * Name : Md. Fahmidur Rahman Nafi
 * Date : 2025-06-13   Time : 20:50:23
 */

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define debug(x) cout << "Debug : " << x << endl;
const double PI = 2 * acos(0.0);
const int MOD = 1000000007;

void solve(){
    int n;
    cin >> n;
    vector <ll> a(n), b(n), A, B;
    for (auto &i : a) cin >> i;
    for (auto &i : b) cin >> i;
    
    sort(b.begin(), b.end());
    sort(a.begin(), a.end());

    if (n == 1){
        cout << "Yes" << endl;
        return;
    }
    else if (n == 2){
        if (a[1] > b[0] || b[1] > a[1]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        A = a;
        B = b;

        swap(b[1], b[2]);

        A.erase(A.begin());
        bool ok = true;
        for (int i = 1; i < n - 1; i++){
            if (A[i] <= b[i - 1] || A[i] <= b[i + 1]){
                ok = false;
                break;
            }
        }

        if (ok){
            cout << "Yes" << endl;
            return;
        }

        ok = true;
        B.erase(B.begin());
        // for (auto i : B) cout << i << ' ';
        swap(a[1], a[2]);
        
        for (int i = 1; i < n - 1; i++){
            if (B[i] <= a[i - 1] || B[i] <= a[i + 1]){
                ok = false;
                break;
            }
        }

        if (!ok){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
}

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

    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 16:44:10
Judged At
2025-06-13 16:44:10
Judged By
Score
5
Total Time
21ms
Peak Memory
788.0 KiB