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 <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ranges;
int n;
bool compare(pair<int, int> p1, pair<int, int> p2){
return (p1.second < p2.second) || ((p1.second == p2.second && p1.first < p2.first));
}
void init(int N, int A[], int B[]) {
n = N;
for(int i = 0; i < N; i++) ranges.push_back({A[i], B[i]});
sort(ranges.begin(), ranges.end(), compare);
}
int can(int M, int K[]) {
vector<bool> assigned(n, false);
sort(K, K+M);
int init = 0;
for(int i = 0; i < M; i++){
int cnt = 0;
bool ok = false;
// naive O(N)
// posso contare il numero di studenti che vanno bene tramite una binary search
// però poi come li marchio assegnati?
for(int j = init; j < n; j++){
int start = ranges[j].first;
int end = ranges[j].second;
if(start <= K[i] && end >= K[i] && !assigned[j]) cnt++, assigned[j] = true;
if(cnt == K[i]){ok = true; init=j+1; break;}
}
// logn O(logN)
// contare il numero di intervalli che contengono un'altro intervallo
// A = cnt({K[i], K[i+1]})
// B = cnt({K[i+1], K[i+1]}) B - A se A <= K[i], altrimenti tolgo K[i]
if(!ok) return 0;
}
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... |