/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は、果樹園の管理人です。この果樹園には N 本の果樹が植えられており、それぞれ 1, 2, \ldots, N と番号が付けられています。果樹 i の高さは H_i です。
昨夜、大型の台風がこの地域を通過しました。台風の強風により、高さが T 以下の果樹はまだ根が十分に張っておらず、すべて倒れてしまいました。すなわち、果樹 i は H_i \leq T を満たすとき、またそのときに限り倒れています。
高橋君は果樹園を復旧するため、倒れた果樹をすべて植え直すことにしました。果樹 i を植え直して元の状態に戻すには C_i のコストがかかります。
倒れたすべての果樹を元の状態に戻すために必要な総コストを求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq T \leq 10^9
- 1 \leq H_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq C_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数
- 答えは 2 \times 10^{14} 以下であることが保証される
入力
入力は以下の形式で標準入力から与えられる。
N T H_1 H_2 \ldots H_N C_1 C_2 \ldots C_N
- 1 行目には、果樹の本数を表す整数 N と、果樹が倒れる高さの基準値を表す整数 T が、スペース区切りで与えられる。
- 2 行目には、各果樹の高さを表す整数 H_1, H_2, \ldots, H_N が、スペース区切りで与えられる。
- 3 行目には、各果樹を植え直す際の復旧コストを表す整数 C_1, C_2, \ldots, C_N が、スペース区切りで与えられる。
出力
倒れた果樹(H_i \leq T を満たす果樹 i)をすべて元に戻すために必要な総コストを 1 行で出力せよ。倒れた果樹が 1 本もない場合は 0 を出力せよ。末尾に改行を含めること。
入力例 1
5 3 1 5 3 4 2 10 20 30 40 50
出力例 1
90
入力例 2
4 2 5 10 8 3 100 200 300 400
出力例 2
0
入力例 3
10 50 10 20 30 40 50 60 70 80 90 100 5 15 25 35 45 55 65 75 85 95
出力例 3
125
入力例 4
20 500 100 200 300 400 500 600 700 800 900 1000 150 250 350 450 550 650 750 850 950 50 10 20 30 40 50 60 70 80 90 100 15 25 35 45 55 65 75 85 95 5
出力例 4
275
入力例 5
1 1000000000 1000000000 999999999
出力例 5
999999999
Score : 200 pts
Problem Statement
Takahashi is the caretaker of an orchard. There are N fruit trees planted in this orchard, numbered 1, 2, \ldots, N. The height of fruit tree i is H_i.
Last night, a large typhoon passed through this area. Due to the typhoon's strong winds, fruit trees with height T or less had not yet developed sufficient roots and all fell over. That is, fruit tree i has fallen if and only if H_i \leq T.
To restore the orchard, Takahashi decided to replant all the fallen fruit trees. The cost to replant fruit tree i and restore it to its original state is C_i.
Find the total cost required to restore all fallen fruit trees to their original state.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq T \leq 10^9
- 1 \leq H_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq C_i \leq 10^9 (1 \leq i \leq N)
- All inputs are integers
- It is guaranteed that the answer is at most 2 \times 10^{14}
Input
Input is given from standard input in the following format.
N T H_1 H_2 \ldots H_N C_1 C_2 \ldots C_N
- The first line contains an integer N representing the number of fruit trees and an integer T representing the height threshold for trees falling, separated by a space.
- The second line contains integers H_1, H_2, \ldots, H_N representing the height of each fruit tree, separated by spaces.
- The third line contains integers C_1, C_2, \ldots, C_N representing the restoration cost for replanting each fruit tree, separated by spaces.
Output
Output in a single line the total cost required to restore all fallen fruit trees (fruit trees i satisfying H_i \leq T). If no fruit trees have fallen, output 0. Include a newline at the end.
Sample Input 1
5 3 1 5 3 4 2 10 20 30 40 50
Sample Output 1
90
Sample Input 2
4 2 5 10 8 3 100 200 300 400
Sample Output 2
0
Sample Input 3
10 50 10 20 30 40 50 60 70 80 90 100 5 15 25 35 45 55 65 75 85 95
Sample Output 3
125
Sample Input 4
20 500 100 200 300 400 500 600 700 800 900 1000 150 250 350 450 550 650 750 850 950 50 10 20 30 40 50 60 70 80 90 100 15 25 35 45 55 65 75 85 95 5
Sample Output 4
275
Sample Input 5
1 1000000000 1000000000 999999999
Sample Output 5
999999999