UVa 11292 Dragon of Loowater
简单贪心
龙头的直径和人的佣金排序,价值小的人和直径小的配
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 typedef long long ll; 7 #define N 20005 8 using namespace std; 9 int a[N],b[N]; 10 int main(){ 11 int m,n; 12 int i,j; 13 while(scanf("%d%d",&n,&m)!=EOF){ 14 if(n==0&&m==0) 15 break; 16 for(i=1;i<=n;i++){ 17 scanf("%d",&a[i]); 18 } 19 for(i=1;i<=m;i++){ 20 scanf("%d",&b[i]); 21 } 22 sort(a+1,a+1+n); 23 sort(b+1,b+1+m); 24 int ans=0; 25 int t=1; 26 for(i=1;i<=m;i++){ 27 if(b[i]>=a[t]){ 28 ans=ans+b[i]; 29 t++; 30 if(t-1==n) 31 break; 32 } 33 } 34 if(t-1<n) 35 printf("Loowater is doomed!\n"); 36 else 37 printf("%d\n",ans); 38 } 39 }