题目:Dragon of Loowater
思路:贪心,每个头都让刚好能砍掉这个头的能力最差的人砍。
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<algorithm>
#include<cmath>
using namespace std;int a[20005]={0},b[20005]={0};
int n,m;int Do(){sort(a+1,a+n+1);sort(b+1,b+m+1);int j=1;int sum=0;for(int i=1;i<=n;i++){if(a[i]>b[j]) i--;else sum+=b[j];j++;}if(j>m+1) return -1;return sum;}int main() {while(~scanf("%d%d",&n,&m)&&n!=0){for(int i=1;i<=n;i++){int d;scanf("%d",&d);a[i]=d;}for(int i=1;i<=m;i++){int x;scanf("%d",&x);b[i]=x;}int ans=-1;if(n<=m){ans=Do();}if(ans==-1){printf("Loowater is doomed!\n");}else printf("%d\n",ans);}return 0;
}