Submission #1267667

#TimeUsernameProblemLanguageResultExecution timeMemory
1267667alexandrosGift Exchange (JOI24_ho_t4)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<ll> A, B;
vector<ll> as, bs;

string safe_check(ll start, ll end) {
    start--;
    end--;
    ll m = end - start + 1;
    if (m <= 1) return "No\n";

    vector<pair<ll, ll>> gifts;
    for (ll i = start; i <= end; i++) {
        gifts.emplace_back(A[i], i);
    }
    vector<pair<ll, ll>> wants;
    for (ll i = start; i <= end; i++) {
        wants.emplace_back(B[i], i);
    }

    sort(gifts.rbegin(), gifts.rend());
    sort(wants.rbegin(), wants.rend());

    vector<bool> used(m, false);

    for (auto& [need, recipient] : wants) {
        bool found = false;
        for (int i = 0; i < m; i++) {
            ll giver_idx = gifts[i].second;
            if (!used[i] && giver_idx != recipient && gifts[i].first >= need) {
                used[i] = true;
                found = true;
                break;
            }
        }
        if (!found) return "No\n";
    }

    return "Yes\n";
}

int main() {
    bool asort = true, bsort = true;
    ll amount, amountq;
    ll temp1, temp2;
    scanf("%lld", &amount);
    A.resize(amount);
    B.resize(amount);
    for (int i = 0; i < amount; i++) 
    {
        scanf("%lld", &A[i]);
        if(i > 0 && A[i] < A[i-1]) asort = false;
    }
    for (int i = 0; i < amount; i++)
    {
        scanf("%lld", &B[i]);
        if(i > 0 && B[i] < B[i-1]) bsort = false;
    }
    scanf("%lld", &amountq);
    for(int i = 0; i < amountq; i++)
    {
        scanf("%lld %lld", &temp1, &temp2);
        cout << safe_check(temp1, temp2);
    }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     scanf("%lld", &amount);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         scanf("%lld", &A[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%lld", &B[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |     scanf("%lld", &amountq);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         scanf("%lld %lld", &temp1, &temp2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...