A - Air Conditioner Temperature Adjustment

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233 点

問題文

高橋君はオフィスビルの空調管理を担当しています。今日、ビル内の N 個の部屋の温度をチェックすることになりました。

快適なオフィス環境のため、各部屋の温度は 37 度以下に保つ必要があります。温度が 37 度より高い部屋は、エアコンを使って冷却しなければなりません。温度が既に 37 度以下の部屋は冷却の必要がありません。

i 番目の部屋 (1 \leq i \leq N) の現在の温度は T_i 度です。高橋君は 1 回の操作で、N 個の部屋から 1 つを選び、その部屋の温度をちょうど 0.1 度下げることができます。同じ部屋を複数回選ぶこともできます。

すべての部屋の温度を 37 度以下にするために必要な操作の合計回数の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0.0 \leq T_i \leq 50.0
  • T_i は小数第 1 位までの実数である(すなわち、10 \times T_i は整数である)
  • 入力において、各 T_i は必ず小数第 1 位まで表記される(例:整数値であっても 37.0 のように与えられる)

入力

N
T_1 T_2 \cdots T_N
  • 1 行目には、部屋の数を表す整数 N が与えられる。
  • 2 行目には、各部屋の温度(度)を表す T_1, T_2, \ldots, T_N が、スペース区切りで与えられる。
  • 各 T_i は小数第 1 位までの表記で与えられる。

出力

すべての部屋の温度を 37 度以下にするために必要な操作の合計回数の最小値を、整数で 1 行に出力せよ。


入力例 1

3
36.5 37.0 38.2

出力例 1

12

入力例 2

5
37.3 40.0 36.0 38.5 37.0

出力例 2

48

入力例 3

10
35.0 37.5 42.0 37.0 39.8 36.9 50.0 38.0 37.1 41.5

出力例 3

269

Score : 233 pts

Problem Statement

Takahashi is in charge of air conditioning management for an office building. Today, he needs to check the temperatures of N rooms in the building.

For a comfortable office environment, the temperature of each room must be kept at 37 degrees or below. Rooms with temperatures higher than 37 degrees must be cooled using air conditioners. Rooms whose temperatures are already 37 degrees or below do not need cooling.

The current temperature of the i-th room (1 \leq i \leq N) is T_i degrees. In one operation, Takahashi can choose one of the N rooms and lower its temperature by exactly 0.1 degrees. The same room can be chosen multiple times.

Find the minimum total number of operations required to make the temperature of every room 37 degrees or below.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0.0 \leq T_i \leq 50.0
  • T_i is a real number with exactly one decimal place (i.e., 10 \times T_i is an integer)
  • In the input, each T_i is always written with exactly one decimal place (e.g., even integer values are given as 37.0)

Input

N
T_1 T_2 \cdots T_N
  • The first line contains an integer N, representing the number of rooms.
  • The second line contains T_1, T_2, \ldots, T_N, representing the temperature (in degrees) of each room, separated by spaces.
  • Each T_i is given with exactly one decimal place.

Output

Print the minimum total number of operations required to make the temperature of every room 37 degrees or below, as an integer on a single line.


Sample Input 1

3
36.5 37.0 38.2

Sample Output 1

12

Sample Input 2

5
37.3 40.0 36.0 38.5 37.0

Sample Output 2

48

Sample Input 3

10
35.0 37.5 42.0 37.0 39.8 36.9 50.0 38.0 37.1 41.5

Sample Output 3

269
B - Product Selection

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

高橋君はデパートのバイヤーです。今度開催される特別セールに向けて、倉庫から商品を選んで売り場に並べることになりました。

倉庫には N 個の商品があり、i 番目の商品 (1 \leq i \leq N) には販売価格 V_i が設定されています。また、倉庫は 1 から M までの番号が付いた M 個のエリアに分かれており、i 番目の商品はエリア C_i に保管されています。

倉庫のエリアの中には改装工事中のため立ち入ることができないものがあります。立ち入り可能なエリアは Q 個あり、そのエリア番号は S_1, S_2, \ldots, S_Q として与えられます。これら以外のエリアには立ち入ることができません。

高橋君は、立ち入り可能なエリアに保管されている商品の中から K 個以下(0 個でもよい)を選んで売り場に並べます。各商品は最大 1 回しか選べません。売り場のスペースの都合上、K 個を超える商品を並べることはできません。

売り場に並べる商品の販売価格の合計の最大値を求めてください。なお、商品を 1 個も並べない場合の販売価格の合計は 0 とします。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 10^5
  • 1 \leq K \leq N
  • 1 \leq Q \leq M
  • 1 \leq V_i \leq 10^9
  • 1 \leq C_i \leq M
  • 1 \leq S_j \leq M
  • S_1, S_2, \ldots, S_Q はすべて異なる
  • 入力はすべて整数

入力

N M K Q
V_1 C_1
V_2 C_2
\vdots
V_N C_N
S_1 S_2 \ldots S_Q
  • 1 行目には、商品の数 N、エリアの数 M、売り場に並べられる商品の最大数 K、立ち入り可能なエリアの数 Q が、スペース区切りで与えられる。
  • 続く N 行のうち i 行目 (1 \leq i \leq N) には、i 番目の商品の販売価格 V_i と、その商品が保管されているエリア番号 C_i が、スペース区切りで与えられる。
  • 最後の行には、立ち入り可能なエリアの番号 S_1, S_2, \ldots, S_Q が、スペース区切りで与えられる。

出力

売り場に並べる商品の販売価格の合計の最大値を 1 行で出力せよ。


入力例 1

5 3 2 2
100 1
200 2
150 1
300 3
50 2
1 2

出力例 1

350

入力例 2

8 5 4 3
500 1
300 2
800 3
150 4
600 2
250 5
400 1
100 3
2 3 5

出力例 2

1950

入力例 3

12 6 5 4
1000000000 1
999999999 2
888888888 3
777777777 4
666666666 5
555555555 6
444444444 1
333333333 2
222222222 3
111111111 4
100000000 5
50000000 6
1 2 4 6

出力例 3

3777777775

Score : 300 pts

Problem Statement

Takahashi is a buyer for a department store. For an upcoming special sale, he needs to select products from the warehouse and display them on the sales floor.

There are N products in the warehouse, and the i-th product (1 \leq i \leq N) has a selling price of V_i. The warehouse is divided into M areas numbered from 1 to M, and the i-th product is stored in area C_i.

Some areas of the warehouse are inaccessible due to renovation work. There are Q accessible areas, and their area numbers are given as S_1, S_2, \ldots, S_Q. All other areas are inaccessible.

Takahashi will select at most K products (possibly 0) from those stored in accessible areas and display them on the sales floor. Each product can be selected at most once. Due to space limitations on the sales floor, no more than K products can be displayed.

Find the maximum possible total selling price of the products displayed on the sales floor. Note that if no products are displayed, the total selling price is 0.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 10^5
  • 1 \leq K \leq N
  • 1 \leq Q \leq M
  • 1 \leq V_i \leq 10^9
  • 1 \leq C_i \leq M
  • 1 \leq S_j \leq M
  • S_1, S_2, \ldots, S_Q are all distinct
  • All inputs are integers

Input

N M K Q
V_1 C_1
V_2 C_2
\vdots
V_N C_N
S_1 S_2 \ldots S_Q
  • The first line contains the number of products N, the number of areas M, the maximum number of products that can be displayed K, and the number of accessible areas Q, separated by spaces.
  • The i-th of the following N lines (1 \leq i \leq N) contains the selling price V_i of the i-th product and the area number C_i where it is stored, separated by a space.
  • The last line contains the area numbers of the accessible areas S_1, S_2, \ldots, S_Q, separated by spaces.

Output

Print the maximum possible total selling price of the products displayed on the sales floor in a single line.


Sample Input 1

5 3 2 2
100 1
200 2
150 1
300 3
50 2
1 2

Sample Output 1

350

Sample Input 2

8 5 4 3
500 1
300 2
800 3
150 4
600 2
250 5
400 1
100 3
2 3 5

Sample Output 2

1950

Sample Input 3

12 6 5 4
1000000000 1
999999999 2
888888888 3
777777777 4
666666666 5
555555555 6
444444444 1
333333333 2
222222222 3
111111111 4
100000000 5
50000000 6
1 2 4 6

Sample Output 3

3777777775
C - Comparing Streetlight Brightness

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 366 点

問題文

高橋君と青木君は、それぞれ別の道路で街灯の管理を担当しています。

各道路には複数の街灯があります。各街灯に対して、ちょうど1回の点灯操作が整数時刻に行われます。整数時刻 t に点灯操作が行われた街灯は、時刻 t, t+1, \ldots, t + D - 1 の D 個の整数時刻において点灯しています。

ある道路の、ある整数時刻における明るさとは、その時刻にその道路で点灯している街灯の個数のことです。同じ時刻に複数の街灯が点灯していれば、それぞれ別々に1個ずつ数えます。

高橋君は自分の道路にある N 個の街灯に対してそれぞれ1回ずつ点灯操作を行いました。i 番目 (1 \leq i \leq N) の街灯の点灯操作を行った時刻は A_i です。

青木君は自分の道路にある M 個の街灯に対してそれぞれ1回ずつ点灯操作を行いました。j 番目 (1 \leq j \leq M) の街灯の点灯操作を行った時刻は B_j です。

なお、同じ道路内で複数の異なる街灯に対して同じ時刻に点灯操作が行われることもあります。また、A_1, A_2, \ldots, A_N および B_1, B_2, \ldots, B_M はそれぞれ昇順に並んでいるとは限りません。

ある整数時刻において、高橋君の道路の明るさが青木君の道路の明るさより真に大きいとき、その時刻では高橋君の道路のほうが明るいと言います。

時刻 1 以上 T 以下の整数時刻のうち、高橋君の道路のほうが明るい時刻の総数を求めてください。

なお、点灯操作の時刻やその後の点灯期間が時刻 T を超える場合がありますが、数える対象は時刻 1 以上 T 以下の整数時刻のみです。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq D \leq 10^9
  • 1 \leq T \leq 10^9
  • 1 \leq A_i \leq T (1 \leq i \leq N)
  • 1 \leq B_j \leq T (1 \leq j \leq M)
  • 入力はすべて整数である

入力

N M D T
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M
  • 1 行目には、高橋君の街灯の個数 N、青木君の街灯の個数 M、街灯の点灯持続時間 D、考慮する時刻の上限 T が空白区切りで与えられる。
  • 2 行目には、高橋君の各街灯の点灯操作時刻 A_1, A_2, \ldots, A_N が空白区切りで与えられる。
  • 3 行目には、青木君の各街灯の点灯操作時刻 B_1, B_2, \ldots, B_M が空白区切りで与えられる。

出力

時刻 1 以上 T 以下の整数時刻のうち、高橋君の道路のほうが明るい時刻の個数を 1 行で出力せよ。


入力例 1

3 2 3 8
1 4 4
2 5

出力例 1

4

入力例 2

4 3 1 6
3 1 3 6
1 2 3

出力例 2

2

入力例 3

12 10 5 30
3 10 10 1 25 18 7 22 14 14 29 5
2 8 8 12 16 20 24 28 30 4

出力例 3

15

入力例 4

30 28 7 100
5 12 12 18 25 31 37 42 42 49 53 60 67 70 75 80 85 90 95 99 1 8 15 22 29 36 43 50 57 64
3 10 17 24 24 31 38 45 52 59 66 73 80 87 94 100 6 13 20 27 34 41 48 55 62 69 76 83

出力例 4

28

入力例 5

1 1 1 1
1
1

出力例 5

0

Score : 366 pts

Problem Statement

Takahashi and Aoki are each responsible for managing street lights on different roads.

Each road has multiple street lights. For each street light, exactly one lighting operation is performed at an integer time. A street light whose lighting operation is performed at integer time t is lit at the D integer times t, t+1, \ldots, t + D - 1.

The brightness of a road at a given integer time is the number of street lights that are lit on that road at that time. If multiple street lights are lit at the same time, each one is counted separately.

Takahashi performed a lighting operation exactly once for each of the N street lights on his road. The lighting operation for the i-th (1 \leq i \leq N) street light was performed at time A_i.

Aoki performed a lighting operation exactly once for each of the M street lights on his road. The lighting operation for the j-th (1 \leq j \leq M) street light was performed at time B_j.

Note that multiple different street lights on the same road may have their lighting operations performed at the same time. Also, A_1, A_2, \ldots, A_N and B_1, B_2, \ldots, B_M are not necessarily given in ascending order.

At a given integer time, if the brightness of Takahashi's road is strictly greater than the brightness of Aoki's road, we say that Takahashi's road is brighter at that time.

Among the integer times from time 1 to time T inclusive, find the total number of times when Takahashi's road is brighter.

Note that the lighting operation times or the subsequent lighting periods may exceed time T, but only integer times from 1 to T inclusive are counted.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq D \leq 10^9
  • 1 \leq T \leq 10^9
  • 1 \leq A_i \leq T (1 \leq i \leq N)
  • 1 \leq B_j \leq T (1 \leq j \leq M)
  • All inputs are integers

Input

N M D T
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M
  • The first line contains the number of Takahashi's street lights N, the number of Aoki's street lights M, the lighting duration D, and the upper limit of time to consider T, separated by spaces.
  • The second line contains the lighting operation times A_1, A_2, \ldots, A_N for each of Takahashi's street lights, separated by spaces.
  • The third line contains the lighting operation times B_1, B_2, \ldots, B_M for each of Aoki's street lights, separated by spaces.

Output

Output in one line the number of integer times from time 1 to time T inclusive when Takahashi's road is brighter.


Sample Input 1

3 2 3 8
1 4 4
2 5

Sample Output 1

4

Sample Input 2

4 3 1 6
3 1 3 6
1 2 3

Sample Output 2

2

Sample Input 3

12 10 5 30
3 10 10 1 25 18 7 22 14 14 29 5
2 8 8 12 16 20 24 28 30 4

Sample Output 3

15

Sample Input 4

30 28 7 100
5 12 12 18 25 31 37 42 42 49 53 60 67 70 75 80 85 90 95 99 1 8 15 22 29 36 43 50 57 64
3 10 17 24 24 31 38 45 52 59 66 73 80 87 94 100 6 13 20 27 34 41 48 55 62 69 76 83

Sample Output 4

28

Sample Input 5

1 1 1 1
1
1

Sample Output 5

0
D - Safe Climbing Route

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

高橋君は山岳地帯をハイキングすることにしました。この山岳地帯には N 個の地点と M 本の登山道があり、各登山道は双方向に通行できます。高橋君は地点 1 にある登山口から地点 N にある山頂を目指しています。

各地点 i (1 \leq i \leq N) には「危険度」P_i が設定されています。これは、その地点における落石や崖崩れなどの自然災害のリスクの高さを表す指標です。また、j 番目 (1 \leq j \leq M) の登山道は地点 U_j と地点 V_j を双方向に結んでおり、通過するのに時間 W_j がかかります。なお、地点での滞在時間は考えないものとします。

高橋君は地点 1 から出発し、登山道を繰り返したどって地点 N に到着します。このとき、同じ地点や同じ登山道を複数回通ることも許されます。経路の所要時間は、通過した登山道の時間の合計とします。また、経路の危険度は、出発地点 1 と到着地点 N を含む、経路上で訪れるすべての地点の危険度の最大値とします。

高橋君はできるだけ安全にハイキングを楽しみたいと考えていますが、日没までに山頂に到着する必要があります。具体的には、所要時間が T 以下であるような経路の中で、経路の危険度を最小化したいです。

地点 1 から地点 N まで所要時間 T 以下で到達できる経路が少なくとも1つ存在することが保証されます。条件を満たす経路における危険度の最小値を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^4
  • 1 \leq M \leq 4 \times 10^4
  • 1 \leq T \leq 10^9
  • 0 \leq P_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq U_j, V_j \leq N (1 \leq j \leq M)
  • U_j \neq V_j (1 \leq j \leq M)
  • 1 \leq W_j \leq 10^9 (1 \leq j \leq M)
  • 同じ2地点を結ぶ登山道が複数存在することがある。
  • 地点 1 から地点 N まで所要時間 T 以下で到達できる経路が少なくとも1つ存在する。
  • 入力はすべて整数である。

入力

N M T
P_1 P_2 \ldots P_N
U_1 V_1 W_1
U_2 V_2 W_2
\vdots
U_M V_M W_M
  • 1 行目には、地点の数 N 、登山道の数 M 、所要時間の上限 T が、スペース区切りで与えられる。
  • 2 行目には、各地点の危険度 P_1, P_2, \ldots, P_N が、スペース区切りで与えられる。P_i は地点 i の危険度を表す。
  • 3 行目から 2 + M 行目までの M 行では、各登山道の情報が与えられる。
  • 2 + j 行目 (1 \leq j \leq M) には、j 番目の登山道が結ぶ2地点 U_j, V_j と、通過にかかる時間 W_j が、スペース区切りで与えられる。

出力

所要時間が T 以下である経路における危険度の最小値を 1 行で出力せよ。


入力例 1

4 4 7
5 2 8 4
1 2 3
2 4 3
1 3 2
3 4 6

出力例 1

5

入力例 2

5 7 9
3 8 2 7 4
1 2 10
1 2 3
2 5 6
1 3 2
3 4 2
4 5 6
3 5 9

出力例 2

8

入力例 3

10 18 25
10 30 5 40 20 15 60 25 35 12
1 2 5
2 10 15
1 3 4
3 6 7
6 10 12
3 4 3
4 10 5
1 5 10
5 8 5
8 10 9
2 5 2
5 6 2
6 7 3
7 10 3
2 3 8
4 8 2
8 9 4
9 10 4

出力例 3

15

入力例 4

20 40 100
50 12 80 7 30 65 18 90 22 55 5 70 35 42 15 100 28 60 10 40
1 2 10
2 4 10
4 7 8
7 11 12
11 15 10
15 19 9
19 20 8
1 3 5
3 6 5
6 10 15
10 14 10
14 20 20
1 5 20
5 9 10
9 13 15
13 17 10
17 20 20
2 5 6
5 7 7
7 9 5
9 11 6
11 13 7
13 15 5
15 17 6
17 19 4
3 8 12
8 12 8
12 16 10
16 20 25
4 8 20
6 12 15
10 16 10
14 18 6
18 20 10
2 6 30
5 10 25
9 14 20
13 18 12
3 4 50
12 19 30

出力例 4

50

入力例 5

2 1 1000000000
0 1000000000
1 2 1000000000

出力例 5

1000000000

Score : 400 pts

Problem Statement

Takahashi has decided to go hiking in a mountainous area. This area consists of N points and M trails, where each trail can be traversed in both directions. Takahashi starts at the trailhead at point 1 and aims to reach the summit at point N.

Each point i (1 \leq i \leq N) has a "danger level" P_i assigned to it. This represents the level of risk of natural disasters such as rockfalls or landslides at that point. Additionally, the j-th (1 \leq j \leq M) trail bidirectionally connects point U_j and point V_j, and it takes W_j time to traverse. We assume that the time spent staying at any point is negligible.

Takahashi starts from point 1 and repeatedly traverses trails to reach point N. He is allowed to visit the same point or traverse the same trail multiple times. The travel time of a route is the sum of the times of the traversed trails. The danger level of a route is the maximum danger level among all points visited along the route, including the start point 1 and the destination point N.

Takahashi wants to enjoy hiking as safely as possible, but he must reach the summit before sunset. Specifically, he wants to minimize the danger level of the route among all routes whose travel time is at most T.

It is guaranteed that there is at least one route from point 1 to point N with a travel time of at most T. Find the minimum possible danger level of a route satisfying the conditions.

Constraints

  • 2 \leq N \leq 2 \times 10^4
  • 1 \leq M \leq 4 \times 10^4
  • 1 \leq T \leq 10^9
  • 0 \leq P_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq U_j, V_j \leq N (1 \leq j \leq M)
  • U_j \neq V_j (1 \leq j \leq M)
  • 1 \leq W_j \leq 10^9 (1 \leq j \leq M)
  • There may be multiple trails connecting the same pair of points.
  • There is at least one route from point 1 to point N with a travel time of at most T.
  • All input values are integers.

Input

N M T
P_1 P_2 \ldots P_N
U_1 V_1 W_1
U_2 V_2 W_2
\vdots
U_M V_M W_M
  • The first line contains the number of points N, the number of trails M, and the maximum travel time T, separated by spaces.
  • The second line contains the danger levels of each point P_1, P_2, \ldots, P_N, separated by spaces. P_i represents the danger level of point i.
  • The next M lines, from the 3rd line to the (2 + M)-th line, provide information about each trail.
  • The (2 + j)-th line (1 \leq j \leq M) contains the two points U_j and V_j connected by the j-th trail, and the travel time W_j, separated by spaces.

Output

Print the minimum danger level of a route with a travel time of at most T in a single line.


Sample Input 1

4 4 7
5 2 8 4
1 2 3
2 4 3
1 3 2
3 4 6

Sample Output 1

5

Sample Input 2

5 7 9
3 8 2 7 4
1 2 10
1 2 3
2 5 6
1 3 2
3 4 2
4 5 6
3 5 9

Sample Output 2

8

Sample Input 3

10 18 25
10 30 5 40 20 15 60 25 35 12
1 2 5
2 10 15
1 3 4
3 6 7
6 10 12
3 4 3
4 10 5
1 5 10
5 8 5
8 10 9
2 5 2
5 6 2
6 7 3
7 10 3
2 3 8
4 8 2
8 9 4
9 10 4

Sample Output 3

15

Sample Input 4

20 40 100
50 12 80 7 30 65 18 90 22 55 5 70 35 42 15 100 28 60 10 40
1 2 10
2 4 10
4 7 8
7 11 12
11 15 10
15 19 9
19 20 8
1 3 5
3 6 5
6 10 15
10 14 10
14 20 20
1 5 20
5 9 10
9 13 15
13 17 10
17 20 20
2 5 6
5 7 7
7 9 5
9 11 6
11 13 7
13 15 5
15 17 6
17 19 4
3 8 12
8 12 8
12 16 10
16 20 25
4 8 20
6 12 15
10 16 10
14 18 6
18 20 10
2 6 30
5 10 25
9 14 20
13 18 12
3 4 50
12 19 30

Sample Output 4

50

Sample Input 5

2 1 1000000000
0 1000000000
1 2 1000000000

Sample Output 5

1000000000
E - Loading Cargo onto a Truck

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433 点

問題文

高橋君は引っ越し業者のアルバイトをしています。倉庫には N 個の荷物があり、i 番目 (1 \leq i \leq N) の荷物の重さは W_i です。

これらの荷物をすべてトラックに積み込んで運ばなければなりません。トラックは必要なだけ何台でも用意でき、各トラックの最大積載量はすべて等しく M です。

荷物の積み込みには以下の条件があります。

  • 各荷物は分割できず、N 個の荷物それぞれをちょうど 1 台のトラックに載せる必要があります。
  • 1 台のトラックに載せた荷物の重さの合計は最大積載量 M 以下でなければなりません。
  • 各トラックによる運搬は 1 回限りです。同じトラックで複数回に分けて運ぶことはできません。

すべての荷物を運ぶために必要なトラックの最小台数を求めてください。

なお、制約 W_i \leq M より各荷物は単体で 1 台のトラックに載せることができるため、必ずすべての荷物を運ぶことができます。

制約

  • 1 \leq N \leq 20
  • 1 \leq M \leq 10^9
  • 1 \leq W_i \leq M (1 \leq i \leq N)
  • 入力はすべて整数である

入力

N M
W_1 W_2 \dots W_N
  • 1 行目には、荷物の個数を表す整数 N と、1 台のトラックの最大積載量を表す整数 M が、スペース区切りで与えられる。
  • 2 行目には、各荷物の重さを表す整数 W_1, W_2, \dots, W_N が、スペース区切りで与えられる。

出力

必要なトラックの台数の最小値を 1 行で出力してください。


入力例 1

4 10
2 5 4 7

出力例 1

2

入力例 2

5 10
6 6 4 4 2

出力例 2

3

入力例 3

10 15
8 7 6 5 4 3 2 9 10 1

出力例 3

4

入力例 4

20 50
24 26 10 40 15 35 5 45 20 30 25 25 12 18 32 8 42 7 13 37

出力例 4

10

入力例 5

1 1000000000
1000000000

出力例 5

1

Score : 433 pts

Problem Statement

Takahashi is working part-time at a moving company. There are N items in the warehouse, and the weight of the i-th item (1 \leq i \leq N) is W_i.

All of these items must be loaded into trucks and transported. We can prepare as many trucks as we need, and each truck has the same maximum capacity of M.

The loading of items must satisfy the following conditions:

  • Each item cannot be divided, and each of the N items must be loaded onto exactly one truck.
  • The total weight of the items loaded onto a single truck must be at most the maximum capacity M.
  • Each truck can make only one trip. It is not possible to make multiple trips with the same truck.

Find the minimum number of trucks required to transport all the items.

Note that because of the constraint W_i \leq M, each item can be loaded onto a truck by itself, so it is always possible to transport all the items.

Constraints

  • 1 \leq N \leq 20
  • 1 \leq M \leq 10^9
  • 1 \leq W_i \leq M (1 \leq i \leq N)
  • All input values are integers.

Input

N M
W_1 W_2 \dots W_N
  • The 1st line contains the integer N, representing the number of items, and the integer M, representing the maximum capacity of a truck, separated by a space.
  • The 2nd line contains the integers W_1, W_2, \dots, W_N, representing the weights of the items, separated by spaces.

Output

Print the minimum number of trucks required in a single line.


Sample Input 1

4 10
2 5 4 7

Sample Output 1

2

Sample Input 2

5 10
6 6 4 4 2

Sample Output 2

3

Sample Input 3

10 15
8 7 6 5 4 3 2 9 10 1

Sample Output 3

4

Sample Input 4

20 50
24 26 10 40 15 35 5 45 20 30 25 25 12 18 32 8 42 7 13 37

Sample Output 4

10

Sample Input 5

1 1000000000
1000000000

Sample Output 5

1