/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 516.0 KiB
#3 Wrong Answer 37ms 880.0 KiB
#4 Wrong Answer 35ms 808.0 KiB

Code

#define ll long long
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
std::string toBinaryString(long long num) {
std::bitset<64> binary(num);
return binary.to_string();
}
long long binaryToLongLong(const std::string& binary) {
std::bitset<64> binarySet(binary);
return static_cast<long long>(binarySet.to_ullong());
}
bool compareByFirst(const std::pair<ll, ll>& a, const std::pair<ll, ll>& b) {
return a.first < b.first; // Ascending order by the first element
}
bool recur(vector<ll>a,vector<ll>b,ll n)
{
    if(n<=2)
    return true;
    else 
    {
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        priority_queue<ll>aaa;
        priority_queue<ll>bbb;
        for(ll i=2;i<n;i++)
        {
            aaa.push(a[i]);
        }
        for(ll i=0;i<n;i++)
        {
            bbb.push(b[i]);
        }
        bool yes=true;
        while(aaa.size())
        {
            if(2*aaa.size()<=bbb.size())
            {
                if(aaa.top()>bbb.top())
                {
                    bbb.pop();
                }
                else 
                yes=false;
                if(aaa.top()>bbb.top())
                {
                    bbb.pop();
                }
                else 
                yes=false;

            }
            else 
            {
                if(aaa.top()>bbb.top())
                {
                    bbb.pop();
                }
                else 
                yes=false;
                if(aaa.top()>bbb.top())
                {
                    ll ss=1;
                }
                else 
                yes=false;
            }
            aaa.pop();
        }
    
    return yes;
    }
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
    long long t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        vector<ll>a(n);
        vector<ll>b(n);
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(ll i=0;i<n;i++)
        {
            cin>>b[i];
        }
        if(recur(a,b,n) || recur(b,a,n))
        cout<<"Yes"<<endl;
        else 
        cout<<"No"<<endl;
    }
}

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:43:46
Judged At
2025-06-13 16:43:46
Judged By
Score
5
Total Time
37ms
Peak Memory
880.0 KiB