# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1098925 | alexander_707070 | Teams (IOI15_teams) | C++14 | 0 ms | 0 KiB |
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>
#include "teams.h"
#define MAXN 500007
using namespace std;
struct interval{
int l,r;
inline friend bool operator < (interval fr,interval sc){
return fr.r>sc.r;
}
}s[MAXN];
bool cmp(interval fr,interval sc){
return fr.l<sc.l;
}
priority_queue<interval> q;
int n,m,a[MAXN],b[MAXN],k[MAXN];
void init(int N, int A[], int B[]) {
//void init(int N, vector<int> A, vector<int> B) {
n=N;
for(int i=1;i<=n;i++){
a[i]=A[i-1]; b[i]=B[i-1];
}
}
int can(int M,int K[]) {
//int can(int M,vector<int> K) {
m=M;
for(int i=1;i<=m;i++){
k[i]=K[i-1];
}
sort(k+1,k+m+1);
for(int i=1;i<=n;i++){
int l=0,r=k+1,tt;
while(l+1<r){
tt=(l+r)/2;
if(k[tt]<=b[i]){
l=tt;
}else{
r=tt;
}
}
s[i].r=l;
l=0; r=k+1;
while(l+1<r){
tt=(l+r)/2;
if(k[tt]>=a[i]){
r=tt;
}else{
l=tt;
}
}
s[i].l=r;
}
sort(s+1,s+n+1,cmp);
while(!q.empty())q.pop();
int pt=1;
for(int i=1;i<=m;i++){
while(pt<=n and s[pt].l<=k[i]){
q.push(s[pt]); pt++;
}
while(!q.empty() and q.top().r<k[i])q.pop();
for(int f=0;f<k[i];f++){
if(q.empty())return 0;
q.pop();
}
}
return 1;
}
/*int main(){
init(4,{1,2,2,2},{2,3,3,4});
cout<<can(2,{1,3})<<"\n";
cout<<can(2,{1,1})<<"\n";
return 0;
}*/