# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165418 | gayporn | Robots (IOI13_robots) | 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.
//Pye
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define pair pair <int, int>
#define F first
#define S second
#define maxn 20005
using namespace std;
int A, B, T, z, tr[maxn], cnt, s, t, maxflow;
pair q[maxn];
struct edge{
int u, v, c, f;
}e[2*maxn];
vector <int> a[maxn];
void add(int u, int v, int c){
a[u].push_back(z);
e[z++] = {u, v, c, 0};
a[v].push_back(z);
e[z++] = {v, u, 0, 0};
}
bool BFS(){
memset(tr, 0, sizeof tr);
tr[s] = -1;
queue <int> q;
q.push(s);
while (q.size()){
int u = q.front(); q.pop();
for (auto id : a[u]){
int v = e[id].v;
if (!tr[v] && e[id].c > e[id].f){
tr[v] = id;
q.push(v);
if(v == t) return 1;
}
}
}
return 0;
}
void IncFlow(){
int delta = 1e9;
int v = t;
while (v != s){
int id = tr[v];
delta = min(delta, e[id].c - e[id].f);
v = e[id].u;
}
v = t;
while (v != s){
int id = tr[v];
e[id].f += delta;
e[id^1].f -= delta;
v = e[id].u;
}
maxflow += delta;
}
bool check(int mid){
for(int i = 0; i < 2*(A + B); i += 2) e[i].c = mid;
for(int i = 0; i < z; i++) e[i].f = 0;
maxflow = 0;
while(BFS()) IncFlow();
return maxflow == T;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// ifstream cin("robots.inp");
// ofstream cout("robots.out");
cin >> A >> B >> T;
s = 10005; t = s+1;
FOR(i, 1, A){
int x; cin >> x;
q[++cnt] = {x, 1e9};
add(s, cnt, 0);
}
FOR(i, 1, B){
int x; cin >> x;
q[++cnt] = {1e9, x};
add(s, cnt, 0);
}
FOR(i, 1, T){
++cnt;
int x, y;
cin >> x >> y;
FOR(j, 1, A+B)
if(q[j].F >= x && q[j].S >= y) add(j, cnt, 1);
add(cnt, t, 1);
}
int l = 0, r = 1e9;
while(r - l > 1){
int mid = (l + r) / 2;
if(check(mid)) r = mid;
else l = mid;
}
cout << r;
}