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 <bits/stdc++.h>
using namespace std;
int N;
int A[100005];
int B[100005];
int C[100005];
int C1[100005];
vector<vector<int> > ind;
void init(int _N, int _A[], int _B[]) {
N = _N;
ind.resize(N+1);
int i;
for(i=0;i<N;i++) A[i] = _A[i];
for(i=0;i<N;i++) B[i] = _B[i];
for(i=0;i<N;i++) C[B[i]]++;
for(i=0;i<N;i++) {
ind[A[i]].push_back(B[i]);
}
}
int D[100005];
int can(int M, int K[]) {
int sum = 0;
memset(D, 0, sizeof(D));
int i;
for(i=1;i<=N;i++) C1[i] = C[i];
for(i=0;i<M;i++) sum += K[i];
if(sum > N) return 0;
for(i=0;i<M;i++) D[K[i]]++;
multiset<int> S;
multiset<int>::iterator iter;
int cnt = 0;
for(i=1;i<=N;i++) {
for(int n : ind[i]) {
S.insert(n);
cnt++;
}
if(cnt > i * D[i]) return 0;
iter = S.begin();
int del = i * D[i];
while(del) {
if(S.count(*iter) == 1) {
auto iter2 = iter++;
del--;
C1[*iter]--;
S.erase(*iter);
iter = iter2;
cnt--;
}
else {
S.erase(*iter);
del--;
C1[*iter]--;
cnt--;
}
}
for(int j=0;j<C1[i];j++) {
S.erase(S.find(i));
cnt--;
}
}
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... |