# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
355959 | sean617 | Robots (IOI13_robots) | C++98 | 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 <iostream>
#include <cstdio>
#include <algorithm>
#define N 1000005
using namespace std;
int n, m, T, l, r, md, cnta, cntb, nm, ans, a[50005], b[50005];
struct str {
int c1, c2, mn, mx;
} c[N];
bool comp(str p, str q) {
if (p.mx != q.mx) return p.mx < q.mx;
return p.mn < q.mn;
}
int main()
{
int i, j, k, t1, t2, w, sz;
bool z;
cin >> n >> m >> T;
for (i = 0; i < n; i++) {
scanf ("%d", &a[i]);
}
for (i = 0; i < m; i++) {
scanf ("%d", &b[i]);
}
nm = max(n, m);
sort(a, a + n);
sort(b, b + m);
for (i = 0; i < T; i++) {
scanf ("%d %d", &w, &sz);
t1 = upper_bound(a, a + n, w) - a;
t2 = upper_bound(b, b + m, sz) - b;
c[i].c1 = n - t1;
c[i].c2 = m - t2;
c[i].mn = min(c[i].c1, c[i].c2);
c[i].mx = max(c[i].c1, c[i].c2);
if (c[i].mx == 0) {
cout << -1;
return 0;
}
}
sort(c, c + T, comp);
// for (i = 0; i < T; i++) {
// printf("%d %d\n", c[i].c1, c[i].c2);
// }
l = 1;
r = T + 1;
while (l < r){
md = (l + r) / 2;
j = 0;
i = 0;
cnta = cntb = 0;
z = 1;
for (k = 1; k <= nm; k++) {
cnta += md;
cntb += md;
for (; i < T; i++) {
if (c[i].mx > k) break;
}
for (; j < i; j++) {
if (c[j].mx < k) {z = 0; break;}
if (cnta > 0 && n >= k) cnta--;
else if (cntb > 0 && m >= k) cntb--;
else {z = 0; break;}
}
if (!z) break;
}
if (z) {r = md; ans = md;}
else l = md+1;
}
cout << ans;
return 0;
}