记录编号 |
351993 |
评测结果 |
AAAAAAAAAA |
题目名称 |
冰桥,升起来了! |
最终得分 |
100 |
用户昵称 |
dududu |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.225 s |
提交时间 |
2016-11-16 20:25:25 |
内存使用 |
1.50 MiB |
显示代码纯文本
#include <cstdio>
#include <utility>
#include <algorithm>
using namespace std;
#define Smax 40003
#define Mmax 100003
typedef pair<int, int> pr;
int A, B, M;
int VA[Smax];
int VB[Smax];
pr Rls[Mmax];
void init() {
scanf("%d %d %d", &A, &B, &M);
for (int i = 1; i <= A; i++)
scanf("%d", VA+i);
for (int i = 1; i <= B; i++)
scanf("%d", VB+i);
for (int i = 0; i < M; i++)
scanf("%d %d", &Rls[i].first, &Rls[i].second);
}
int FA[Smax];
int FB[Smax];
int ans = 0;
void work() {
sort(Rls, Rls+M);
for (int i = 1; i <= A; i++)
FA[i] = VA[i];
for (int i = 1; i <= B; i++)
FB[i] = VB[i];
int a, b, fa, fb;
for (int i = 0; i < M; i++) {
a = Rls[i].first;
b = Rls[i].second;
fa = FA[a];
fb = FB[b];
FA[a] = max(FA[a], fb + VA[a]);
FB[b] = max(FB[b], fa + VB[b]);
}
for (int i = 1; i <= A; i++)
ans = max(ans, FA[i]);
for (int i = 1; i <= B; i++)
ans = max(ans, FB[i]);
printf("%d\n", ans);
}
int main() {
freopen("meibridge.in", "r", stdin);
freopen("meibridge.out", "w", stdout);
init();
work();
return 0;
}