#include<stdio.h> #include <string.h> int main(){ int n,m; //n is number of heads.m is number of knights. while(scanf("%d %d",&n,&m)==2&&!(n==0&&m==0)){ if(n>=1&&n<=20000&&m>=1&&n<=20000&&n<=m){ int headSize[n]; int knightAbility[m]; int i,j; for(i=0;i<n;i++){ scanf("%d\n",&headSize[i]); } for(i=0;i<m;i++){ scanf("%d\n",&knightAbility[i]); } int sum=0; for(i=0;i<n;i++){ int min=999999; for(j=0;j<m;j++){ if(knightAbility[j]>=headSize[i]&&knightAbility[j]<min){ min=knightAbility[j]; } sum+=min; } } printf("%d\n",sum); } else printf("loowater is doomed."); } //printf("end of pro"); }
这道题我没有事先排序,结果不对。
艾尔森