/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 1ms 540.0 KiB
#3 Wrong Answer 22ms 656.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
bool ok(vector<ll> &a, vector<ll> &b)
{
    int n = (int)a.size();
    if (n < 3)
        return true;
    for (int i = 1; i < n - 1; ++i)
        if (!((a[i] > b[i - 1] && a[i] > b[i + 1]) ||
              (b[i] > a[i - 1] && b[i] > a[i + 1])))
            return false;
    return true;
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<ll> a(n), b(n);
        for (auto &x : a)
            cin >> x;
        for (auto &x : b)
            cin >> x;

        if (n < 3)
        {
            cout << "Yes\n";
            continue;
        }
        sort(all(a));
        sort(all(b));
        bool f = false;
        for (int mask = 0; mask < 4 && !f; ++mask)
        {
            vector<ll> ta = a, tb = b;
            if (mask & 1)
                reverse(all(ta));
            if (mask & 2)
                reverse(all(tb));
            f = ok(ta, tb);
        }
        f ? cout << "Yes\n" : cout << "No\n";
    }
}

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:01:10
Judged At
2025-06-13 16:01:10
Judged By
Score
0
Total Time
22ms
Peak Memory
656.0 KiB