이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include "teams.h"
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
// #define endl '\n'
int n;
vi endbefore, beginafter; // both inclusive: before -> <=, after -> >=
void init(int N, int A[], int B[]) {
n = N;
endbefore.resize(n); beginafter.resize(n);
for_(i, 0, n) {
endbefore[B[i]-1]++; beginafter[A[i]-1]++;
}
for_(i, 1, n) endbefore[i] += endbefore[i-1];
for (int i = n-2; i >= 0; i--) beginafter[i] += beginafter[i+1];
}
int can(int M, int K[]) {
// return 0;
for_(i, 0, M) K[i] -= 1;
sort(K, K+M);
int mx = 0;
vi psum(M+1);
for_(i, 0, M) psum[i] += K[i]+1;
for_(i, 1, M+1) psum[i] += psum[i-1];
// cout << "yoyo!" << endl;
vi sufmx(M+1);
for (int i = M; i >= 0; i--) {
int ba;
if (i < M) ba = K[i] < n-1 ? beginafter[K[i]+1] : 0;
else ba = K[M-1] < n-1 ? beginafter[K[M-1]+1] : 0;
sufmx[i] = psum[i] + ba;
if (i < M) sufmx[i] = max(sufmx[i], sufmx[i+1]);
}
// if (K[M-1]+1 < n) {
// int ba = K[M-1]+1 < n ? beginafter[K[M-1]+1] : 0;
// int eb = K[M-1]-1 >= 0 ? endbefore[K[M-1]-1] : 0;
// mx = K[M-1]+1 + ba + eb;
// }
for_(i, 0, M) {
int val = (K[i] >= 1 ? endbefore[K[i]-1] : 0) - (i > 0 ? psum[i-1] : 0) + sufmx[i];
mx = max(mx, val);
}
return mx <= n;
}
// int main() {
// #ifdef mlocal
// freopen("teams.in", "r", stdin);
// #endif
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// int t; cin >> t;
// cout << "got " << t << endl;
// while (t--) {
// }
// }
# | 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... |