2014
02-12

# Ice Rain

Ice Rain——I was waiting for a girl, or waiting for been addicted to the bitter sea. Love for irrigation in silence. No one considered whether the flowers came out or wither. Love which I am not sure swing left and right. I had no choice but to put my sadness into my heart deeply.

Yifenfei was waiting for a girl come out, but never.
His love is caught by Lemon Demon. So yifenfei ’s heart is “Da Xue Fen Fei” like his name.
The weather is cold. Ice as quickly as rain dropped. Lemon said to yifenfei, if he can solve his problem which is to calculate the value of , he will release his love.
Unluckily, yifenfei was bored with Number Theory problem, now you, with intelligent, please help him to find yifenfei’s First Love.

Given two integers n, k(1 <= n, k <= 109).

Given two integers n, k(1 <= n, k <= 109).

5 4
5 3

5
7

http://acm.hit.edu.cn/hoj/problem/view?id=2620

#include <stdio.h>
#include <stdlib.h>

int compar(const void *a, const void *b);

int main()
{
int n, m;
int diameter[20001], height[20001];
int i, j, k, sum, head;

while (scanf("%d %d", &n, &m) != EOF)
{
if (n == 0 &&m == 0)
break;

for (i = 0; i < n; i++)
scanf("%d", &diameter[i]);
for (i = 0; i < m; i++)
scanf("%d", &height[i]);

if (n > m)
{
printf("Loowater is doomed!\n");
continue;
}

qsort(diameter, n, sizeof(diameter[0]), compar);
qsort(height, m, sizeof(height[0]), compar);

head = sum = k = 0;
for (i = 0; i < n; i++)
{
for (j = k; j < m; j++)
{
if (diameter[i] <= height[j])
{
sum += height[j];
k = ++j;
break;
}
}
}

printf("%d\n", sum);
else
printf("Loowater is doomed!\n");
}

return 0;
}

int compar(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}