uva11292 Dragon of Loowater 水题

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267

刘汝佳《算法竞赛入门经典训练指南》1.1例1

 1 ///2014.4.12
 2 ///uva11292
 3 
 4 #include <iostream>
 5 #include <cstdio>
 6 #include <string>
 7 #include <cmath>
 8 #include <algorithm>
 9 using namespace std;
10 
11 #define maxn 20010
12 int n,m;
13 int A[maxn],B[maxn];
14 int main()
15 {
16     // freopen("in","r",stdin);
17     // freopen("out","w",stdout);
18     while( cin>>n>>m && n && m ){
19         for(int i=0 ; i<n ; i++)
20             cin>>A[i];
21         for(int i=0 ; i<m ; i++)
22             cin>>B[i];
23         sort(A,A+n);
24         sort(B,B+m);
25 
26         int sum = 0;
27         int i,j;
28         i = j = 0;
29         for( ; i<n ; i++){
30             if( j==m ) break;
31             for( ; j<m ; j++){
32                 if( B[j]>=A[i] ){
33                     sum += B[j];
34                     j++;
35                     break;
36                 }
37             }
38         }
39         if( i==n )
40             cout<<sum<<endl;
41         else
42             cout<<"Loowater is doomed!"<<endl;
43     }
44     return 0;
45 }

 

posted @ 2014-04-12 11:31  basement_boy  阅读(83)  评论(0编辑  收藏  举报