比赛 20161116 评测结果 AAAAAAAAAA
题目名称 冰桥,升起来了! 最终得分 100
用户昵称 Fmuckss 运行时间 0.146 s
代码语言 C++ 内存使用 1.69 MiB
提交时间 2016-11-16 11:52:05
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 4e4 + 1;
const int maxm = 1e5 + 1;

struct Edge {
	int fr, to;
	Edge() {}
	Edge(int fr_, int to_) { fr = fr_, to = to_; }
	
	bool operator < (const Edge &b) const {
		return fr == b.fr ? to < b.to : fr < b.fr;
	}
} e[maxm];
unsigned int ans;

#define is_num(x) (x <= '9' and x >= '0')
inline int get_num() {
	char tmp = getchar();
	int res = 0;
	
	while (not is_num(tmp)) tmp = getchar();
	while (    is_num(tmp)) {
		res = res * 10 + (tmp ^ '0');
		tmp = getchar();
	}
	
	return res;
}

unsigned int dpl[maxn], dpr[maxn];
int vl[maxn], vr[maxn];
int n, m, k;

inline void read() {
	n = get_num();
	m = get_num();
	k = get_num();
	
	for (int i = 1; i <= n; ++i) dpl[i] = vl[i] = get_num();
	for (int i = 1; i <= m; ++i) dpr[i] = vr[i] = get_num();
	
	int fr, to;
	for (int i = 1; i <= k; ++i) {
		fr = get_num(), to = get_num();
		e[i] = Edge(fr, to);
	}
}

inline void solve() {
	sort(e + 1, e + k + 1);
	unsigned int now_l, now_r;
	int fr, to;
	
	for (int i = 1; i <= k; ++i) {
		fr = e[i].fr, to = e[i].to;
		
		now_l = dpr[to] + vl[fr];
		now_r = dpl[fr] + vr[to];
		
		if (now_l > dpl[fr]) dpl[fr] = now_l;
		if (now_r > dpr[to]) dpr[to] = now_r;
	}
	
	for (int i = 1; i <= n; i++) if (ans < dpl[i]) ans = dpl[i];
	for (int i = 1; i <= m; i++) if (ans < dpr[i]) ans = dpr[i];
	
	printf("%u\n", ans);
}

int main() {
	freopen("meibridge.in", "r", stdin);
	freopen("meibridge.out", "w", stdout);
	read();
	solve();
	return 0;
}