0%

UVA-11292 Dragon of Loowater

就是贪心思想一怼。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=2e4+10;
int a[maxn],b[maxn],n,m;
int main(){
while(scanf("%d%d",&n,&m)!=EOF&&n&&m){
for(int i=0;i<n;i++) scanf("%d",&a[i]);
for(int i=0;i<m;i++) scanf("%d",&b[i]);
sort(a,a+n);
sort(b,b+m);
int idx_a=0,idx_b=0;
long long ans=0;
while(idx_a<n&&idx_b<m){
if(a[idx_a]<=b[idx_b]){
ans+=b[idx_b];
idx_a++;
idx_b++;
}else idx_b++;
}
if(idx_a==n) printf("%lld\n",ans);
else printf("Loowater is doomed!\n");
}
return 0;
}
如果对您有帮助,请我喝杯奶茶?