This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "teams.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <bitset>
// #include <numeric>
using namespace std;
int n;
int prefix[500010], suffix[500010];
vector<pair<int, int> > pt;
void init(int N, int A[], int B[]) {
n = N;
for(int i = 0; i < n; i++){
prefix[B[i]]++;
suffix[A[i]]++;
}
for(int i = 1; i <= n; i++) prefix[i] += prefix[i - 1];
for(int i = n - 1; i; i--) suffix[i] += suffix[i + 1];
}
int can(int M, int K[]) {
long long sum = 0;
for(int i = 0; i < M; i++) sum += K[i];
if(sum > n) return 0;
sort(K, K + M);
pt.clear();
int cnt = K[0];
for(int i = 1; i < M; i++){
if(K[i] != K[i - 1]){
pt.emplace_back(K[i - 1], cnt);
cnt = K[i];
} else {
cnt += K[i];
}
}
pt.emplace_back(K[M - 1], cnt);
int mn = n - prefix[pt[0].first - 1], pref = 0;
for(auto &k : pt){
if(pref + k.second + suffix[k.first + 1] > mn) return 0;
mn = min(mn, n + pref - prefix[k.first - 1]);
pref += k.second;
}
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |