uva 11292 Dragon of Loowater
5588 ワード
リンク:http://uva.onlinejudge.org/index.php?option=com_オンラインjudge&Itemid=8&page=show_problem&category=&problem=2267&mosssg=Submission+received+with+ID+11118596
View Code
View Code
1 #include <iostream>
2 #include <cstdio>
3 #include <string>
4 #include <cstring>
5 #include <cmath>
6 #include<algorithm>
7 using namespace std;
8 int N, M, i, j;
9 int a[20005], b[20005];
10 int main( )
11 {
12 while( scanf( "%d%d", & N, &M )!= EOF , N+M ){
13 for( i=0; i<N; ++ i )
14 scanf( "%d", a+i );
15 for( j=0; j<M; ++ j )
16 scanf( "%d", b+j );
17 sort( a, a+N );
18 ;
19 sort( b, b+M );
20 int ans=0;
21 for( i=0, j=0; i<N&&j<M ; ){
22 if( a[i]<=b[j] ){
23 ans+=b[j];
24 i++, j++;
25 }
26 else
27 j++;
28 }
29 if( i<N )
30 puts( "Loowater is doomed!" );
31 else
32 printf( "%d
", ans );
33 }
34 return 0;
35 }