标签:image break algo oom lse max using enter main
把骑士能力从高到低排序,如果能砍掉头就用,代码如下
#include<cstdio> #include<algorithm> using namespace std; const int maxn = 20000+5; int A[maxn], B[maxn]; int main() { int n, m; while(scanf("%d%d", &n, &m) == 2 && m && n) { int i; for(i = 0; i < n; i++) scanf("%d", &A[i]); for(i = 0; i < m; i++) scanf("%d", &B[i]); sort(A, A+n); sort(B, B+m); int cur = 0; //需要砍掉头的编号 int cost = 0; //当前总费用 for(i = 0; i < m; i++) { if(B[i] >= A[cur]) { cost += B[i]; //雇佣该骑士 if(++cur == n) //如果砍完头,及时退出循环 break; } } if(cur < n) printf("Loowater is doomed!\n"); else printf("%d\n", cost); } return 0; }
1.1-1 Dragon of Loowater, Uva 11292
标签:image break algo oom lse max using enter main
原文地址:https://www.cnblogs.com/DreamInPal/p/10851947.html