记录编号 |
243522 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HAOI 2009]巧克力 |
最终得分 |
100 |
用户昵称 |
Fmuckss |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.004 s |
提交时间 |
2016-03-30 09:29:50 |
内存使用 |
0.42 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 2e4+5;
int n, m;
int ans = 0;
inline int get_num() {
int ans = 0;
char tmp = getchar();
while(tmp < '0' || tmp > '9') tmp = getchar();
while(tmp <= '9' && tmp >= '0') {
ans = ans*10 + tmp - '0';
tmp = getchar();
}
return ans;
}
struct line {
int v;
bool x;
inline line() {}
inline line(int v_, bool x_) { v = v_, x = x_; }
inline bool operator < (const line &b) const {
return v > b.v;
}
}ls[maxn];
inline void read() {
n = get_num();
m = get_num();
for(int i = 1; i <= n-1; i++) ls[i] = line(get_num(), true);
for(int i = n; i <= n+m-2; i++) ls[i] = line(get_num(), false);
}
inline void solve() {
sort(ls+1, ls+n+m-1);
int x = 1, y = 1;
for(int i = 1; i <= n+m-2; i++) ans += (ls[i].x ? (x++, y) : (y++, x)) * ls[i].v;
}
int main() {
freopen("chocolate.in", "r", stdin);
freopen("chocolate.out", "w", stdout);
read();
solve();
printf("%d", ans);
return 0;
}