Title: A dragon has n. There are M-brave people. The capacity of the brave is greater than the size of the faucet can defeat him, every brave need to be able to value the equal Commission,
Ask to use at least how much money can kill the dragon.
Analysis: Greed. First of all, the Dragon and the brave fight are incremented, and then, every time you hire a brave man who can kill a dragon with the lowest current ability.
(assuming that the current brave leads to an ill-optimized solution, he had a higher commission than he had before, and he must have been hired earlier)
Description: Tian Bogey horse racing (⊙_⊙).
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstdio>using namespace Std;int d[20001];int K[20001];int Main () {int n,m;while (scanf ("%d%d", &n,&m) && n+m) {for (int i = 0; i < n; + + i) scanf ("%d", &d[i]), for (int i = 0; i < m; + + i) scanf ("%d", &k[i]); sort (d, d+n); sort (k, k+m); int now = 0,sum = 0,flag = 0;for (int i = 0; i < n; + + i) {while (now < M && D[i] > K[now]) now ++;if >= m) {flag = 1; break;} else sum + = K[now + +];} if (flag) printf ("Loowater is doomed!\n"), Else printf ("%d\n", sum);} return 0;}
UVa 11292-dragon of Loowater