/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 24ms 576.0 KiB
#4 Accepted 19ms 532.0 KiB
#5 Accepted 24ms 604.0 KiB
#6 Accepted 25ms 788.0 KiB
#7 Accepted 49ms 3.555 MiB
#8 Accepted 47ms 6.52 MiB
#9 Accepted 44ms 6.52 MiB
#10 Accepted 45ms 6.562 MiB
#11 Accepted 9ms 532.0 KiB
#12 Accepted 20ms 592.0 KiB

Code

/*
 *Copyright (c) Swadheen Islam Robi (SIR01)
 *Created on Sat Jun 14 2025 12:49:52 AM
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pie 2*(acos(0.0))
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define pb push_back
#define endl "\n"
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);

void sir()
{
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), x(n), y(n);
    for(auto &e:a) cin>>e;
    for(auto &d:b) cin>>d;

    srt(a); srt(b);

    //peak considering a

    x[0] = a[0], x[n-1] = a[1];

    ll ind = 2;
    for(ll i=1; i<n-1; i+=2) x[i] = a[ind++];
    for(ll i=2; i<n-1; i+=2) x[i] = a[ind++];

    ind = 0;
    for(ll i=0; i<n; i+=2) y[i] = b[ind++];
    for(ll i=1; i<n; i+=2) y[i] = b[ind++];
    
    bool ok = true;
    for(ll i=1; i<n-1; i++)
    {
        if(x[i]<=y[i-1]|| x[i]<=y[i+1])
        {
            ok = false;
            break;
        }
    }

    // for(auto &e:x) cout<<e<<" "; cout<<endl;
    // for(auto &e:y) cout<<e<<" "; cout<<endl;

    if(ok)
    {
        yes;
        return;
    }
    //peak considering a

    x[0] = b[0], x[n-1] = b[1];

    ind = 2;
    for(ll i=1; i<n-1; i+=2) x[i] = b[ind++];
    for(ll i=2; i<n-1; i+=2) x[i] = b[ind++];

    ind = 0;
    for(ll i=0; i<n; i+=2) y[i] = a[ind++];
    for(ll i=1; i<n; i+=2) y[i] = a[ind++];

    ok = true;
    for(ll i=1; i<n-1; i++)
    {
        if(x[i]<=y[i-1]|| x[i]<=y[i+1])
        {
            ok = false;
            break;
        }
    }
    
    // for(auto &e:x) cout<<e<<" "; cout<<endl;
    // for(auto &e:y) cout<<e<<" "; cout<<endl;

    if(ok)
    {
        yes;
        return;
    }

    no;

}

int main() {
    ALLAHU_AKBAR

    ll t = 1;
    cin>>t;
    while(t--)
    {
        sir();
    }
    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-13 20:15:38
Judged At
2025-06-13 20:15:38
Judged By
Score
100
Total Time
49ms
Peak Memory
6.562 MiB