Submission #1328293

#TimeUsernameProblemLanguageResultExecution timeMemory
1328293edoTeams (IOI15_teams)C++20
34 / 100
4094 ms12260 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#include "teams.h"

struct S {
    int A, B;
    bool operator<(const S &other) const {
        return A < other.A;
    }
};

int tot_S;
vector<S> st;

void init(int N, int A[], int B[]) {
    tot_S = N;
    st.resize(N);
    for(int i = 0; i < N; i++) {
        st[i] = {A[i], B[i]};
    }

    sort(st.begin(), st.end());
}

int can(int M, int K[]) {
    ll sum = accumulate(K, K + M, 0LL);
    if(sum > tot_S) 
        return 0;

    vector<int> teams(K, K+M);
    ranges::sort(teams);
    priority_queue<int, vector<int>, greater<>> as;
    int sid = 0;
    for(int k : teams) {
        while(sid < tot_S && st[sid].A <= k) {
            as.push(st[sid++].B);
        }
        while(as.size() && as.top() < k) {
            as.pop();
        }

        if(as.size() < k)
            return 0;

        for(int i = 0; i < k; i++) {
            as.pop();
        }
    }
	return 1;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...