C-Dragon of LoowaterTime
limit:MS
Memory Limit:0KB
64bit IO Format:%lld & %llu SubmitStatusPracticeUVA 11292Appoint Description:System Crawler (2015-07-27)
Description
Problem c:the Dragon of loowateronce upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major proble M.
The shores of Rellau Creek in central Loowater had all been a prime breeding ground for geese. Due to the lack of predators, the geese population is out of control. The people of Loowater mostly kept clear of the geese. Occasionally, a goose would attack one of the people, and perhaps bite off a finger or both, but in general, the people Tol Erated the geese as a minor nuisance.
One day, a freak mutation occurred, and one of the geese spawned a multi-headed fire-breathing dragon. When the dragon grew up, he threatened to burn the kingdom of Loowater to a crisp. Loowater had a major problem. The king was alarmed, and called in his knights to slay the Dragon and save.
The Knights explained: "To slay the dragon, we must chop off all its heads. Each knight can chop off one of the Dragon ' s heads. The heads of the dragon are of different sizes. In order to chop off a head, a knight must is at least as tall as the diameter of the head. The Knights ' union demands that for chopping off a head, a knight must is paid a wage equal to one gold coin for each cent Imetre of the Knight ' s height. "
Would there is enough knights to defeat the dragon? The king called on he advisors to help him decide how many and which knights to hire. After has lost a lot of money building Mir Park, the king wanted to minimize the expense of slaying. As one of the advisors, your job is to help the king. You took it very seriously:if your failed, you and the whole kingdom would is burnt to a crisp!
Input Specification:
The input contains several test cases. The first line of all test case contains integers between 1 and 20000 inclusive, indicating the number n of Heads that the dragon have, and the number m of knights in the kingdom. The next n lines each contain a integer, and give the diameters of the Dragon ' s heads, in centimetres. The following m lines each contain a integer, and specify the heights of the Knights of Loowater, also in Centim Etres.
The last test case was followed by a line containing:
0 0
Output Specification:
For each test case, output a line containing the minimum number of gold coins that the king needs to pay to slay the Drago N. If It is not a possible for the Knights of Loowater to slay the dragon, output the line:
Loowater is doomed!
Sample Input:
2 3547842 155100 0
Output for Sample Input:
11Loowater is doomed!
N Dragon and M warrior Warrior's ability value he[i] Dragon's ability value dr[i] When a warrior's ability is greater than the value of a dragon, Warriors can kill dragons, but the number of gold coins to be consumed and equal in capacity is the minimum amount of coins the warrior kills all the Dragons. If warriors can't kill all dragons, then output
Loowater is doomed!
The idea of solving a problem is simple. The ability values of warriors and dragons are compared to the ability values of the Dragon and the dragon after being sorted from small to large. If you can kill dragons then total gold number + Warrior ability value and switch to the next dragon to do comparison until the dragon is killed light if traverse all warriors still can't kill the Light Dragon output Loowater is Doom ed!
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn = 20000 + 11;int HE[MAXN], dr[maxn];int N, m;int ans, cur;int main () {while (scanf ("%d%d", &n, & AMP;M)!=eof && (n| | m) { for (int i = 0; i < n; ++i) { scanf ("%d", &dr[i]); } for (int i = 0; i < m; ++i) { scanf ("%d", &he[i]); } Sort (he, he+m); Sort (dr, dr+n); Ans = 0; cur = 0; for (int i = 0; i < m; ++i) { if (He[i] >= dr[cur]) { ++cur; Ans + = he[i]; if (cur = = N) {break ; }} } if (cur < n) { printf ("Loowater is doomed!\n"); } else{ printf ("%d\n", ans); } } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"UVA11292" Dragon of Loowater