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 dp = 0, mn = 0;
for(int i = 0; i < (int) pt.size(); i++){
pair<int, int> k = pt[i];
dp = n - suffix[k.first + 1] - k.second + mn;
if(dp < 0) return 0;
if(i < (int) pt.size() - 1) mn = min(mn, dp + prefix[pt[i + 1].first - 1]);
}
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... |