当前位置:网站首页>uva11292
uva11292
2022-06-21 12:28:00 【小刀刺大熊】
你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(即砍掉所有头)。村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币。如何雇佣骑士才能砍掉龙的所有头,且需要支付的金币最少?注意,一个骑士只能砍一个头。(且不能被雇佣两次)。 输入格式
输入包含多组数据。每组数据的第一行为正整数n和m(1<=n,m<=20000);以下n行每行为一个整数,即恶龙每个头的直径;以下m行每行为一个整数,即每个骑士的能力。输入结束标志为n=m=0。 输出格式
对于每组数据,输出最小花费。如果无解,输出“Loowater is doomed!”。
#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 20007;
int n, m;
int a[maxn], b[maxn];
int main()
{
while (cin >> n >> m && n && m) {
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
sort(a, a + n);
sort(b, b + m);
int first = 0, second = 0,ans = 0;
while (first < n) {
bool ok = false;
while (second < m) {
if (a[first] <= b[second]) {
ans += b[second++];
ok = true;
break;
}
second++;
}
if (ok)first++;
else break;
}
if (first == n) cout << ans << endl;
else cout << "Loowater is doomed!" << endl;
}
return 0;
}
边栏推荐
- 方法的繼承和重寫
- "Forget to learn again" shell process control - 36. Introduction to the for loop
- Workbench常见网格划分方法讲解
- STM32笔记之 PWM(脉宽调制)
- [100 unity stepping pit knowledge points] | draw cube dotted line and sphere dotted line (gizmos auxiliary wireframe) in the editor
- 7. 指针
- Version of opengauss
- Schéma technique du système de surveillance de l'environnement de la salle de distribution
- The wechat authorization login window will pop up automatically
- i. MX - rt1052 SPI and I2C interfaces
猜你喜欢
随机推荐
Sdcc compiler + vscode to develop 8-bit microcontroller
Educoder Web练习题---结构元素
[100 unity practical skills] | obtain the coordinates of mouse clicks in the game and move the game object to the click position of the mouse
3D Slicer将分割结果保存
Three structures of program - system learning I
自定义view绘制折线图(支持缩放)
channels详细使用说明
给表单组件添加说明
常用的17个运维监控系统
~~~~Configuration
i. MX - rt1052 input / output (GPIO)
Corrigendum to 138 sets of reference solutions to the real problems of Higher Algebra in 2022
配电室环境监控系统技术方案
SDCC编译器 + VSCode开发 8位微控制器
Travel does not heal the soul
愿山河无恙
8. 结构体
网页加载时waiting(TTFB)时间过长的问题解决
Understand UML class diagram and sequence diagram
These three young men are more ruthless than Ma Huateng and Zhang Yiming









