UVA 11292
训练指南 第一章 例1
两个数组排序后贪心处理即可,水题一道。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ms(i, j) memeset(i, j, sizeof i)
#define FN2 "UVA11292"
const int MAXN = 20000 + 5;
int n, m, di[MAXN], ki[MAXN];
void init() {
for (int i=1;i<=n;i++) scanf("%d", &di[i]);
for (int i=1;i<=m;i++) scanf("%d", &ki[i]);
}
void solve() {
sort(di+1, di+1+n), sort(ki+1, ki+1+m);
int l = 1, ans = 0;
for (int i=1;i<=m;i++) {
if (ki[i]>=di[l]) ans += ki[i], l++;
if (l>n) break;
}
if (l<=n) printf("Loowater is doomed!\n"); else printf("%d\n", ans);
}
int main() {
//freopen(FN2".in", "r", stdin); freopen(FN2".out", "w", stdout);
while (scanf("%d%d", &n, &m)==2&&n&&m) init(), solve();
return 0;
}