#include "bits/stdc++.h"
using namespace std;
int main(int argc, char const *argv[]) {
int n, m;
while (scanf("%d%d", &n, &m), n || m) {
int dir[20050] = { 0 };
int abl[20050] = { 0 };
for (size_t i = 0; i < n; ++i)
scanf("%d", &dir[i]);
for (size_t i = 0; i < m; ++i)
scanf("%d", &abl[i]);
sort(dir, dir + n);
sort(abl, abl + m);
int cost = 0, OKdra = 0;
for (size_t i = 0; i < m && OKdra < n; ++i)
if (dir[OKdra] <= abl[i]) { cost += abl[i]; OKdra +=1; }
if (OKdra < n) puts ("Loowater is doomed!");
else printf("%d\n", cost);
}
return 0;
}
AOAPC:Chapter1Example1 (UVa 11292)
最新推荐文章于 2024-06-02 09:56:27 发布
本文展示了一段使用C++解决特定问题的程序代码。该程序通过读取输入数据并进行排序来解决一个关于资源分配的问题。具体而言,程序接收两个整数n和m作为输入,分别代表待处理的数组大小,并进一步读取这些数组的内容,然后对其进行排序以找出最优的配对方案。

1万+

被折叠的 条评论
为什么被折叠?



