A - Bacteria Growth Experiment

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 166

問題文

高橋君は生物学の研究室でバクテリアの増殖実験を行っています。

この実験では、特殊な培養液の中でバクテリアのコロニーが成長します。各コロニーは一定時間ごとに分裂し、元のコロニーのちょうど 2 倍のサイズを持つ新しいコロニーが生まれます。

実験開始時、培養液にはサイズ 1 のコロニーが 1 つだけ存在します。その後、以下の増殖が K 回発生します。

増殖: 現在存在するすべてのコロニーそれぞれについて、そのコロニーのサイズを 2 倍にした新しいコロニーが 1 つ生まれる。このとき、元のコロニーもそのまま残る。

つまり、増殖が起こるたびにコロニーの数が増えることになります。ただし、同じサイズのコロニーが複数存在する場合がありますが、研究ではサイズごとに分類して記録するため、同じサイズのものは 1 種類としてカウントします。

K 回の増殖が終わった後、培養液に存在するコロニーは何種類あるでしょうか?言い換えると、存在するコロニーのサイズとして現れる異なる値の個数を求めてください。

制約

  • 1 \leq K \leq 10^{18}
  • K は整数

入力

K
  • 1 行目には、増殖の回数を表す整数 K が与えられる。

出力

K 回の増殖後に存在するコロニーの種類数(異なるサイズの個数)を 1 行で出力してください。


入力例 1

2

出力例 1

3

入力例 2

10

出力例 2

11

入力例 3

1000000000000000000

出力例 3

1000000000000000001

Score : 166 pts

Problem Statement

Takahashi is conducting a bacteria growth experiment in a biology laboratory.

In this experiment, bacteria colonies grow in a special culture medium. Each colony divides at regular intervals, and a new colony with exactly 2 times the size of the original colony is born.

At the start of the experiment, there is only 1 colony of size 1 in the culture medium. After that, the following growth occurs K times.

Growth: For each colony that currently exists, a new colony with twice the size of that colony is born. At this time, the original colony also remains.

In other words, the number of colonies increases each time growth occurs. However, there may be multiple colonies of the same size, but since the research records them classified by size, colonies of the same size are counted as 1 type.

After K growths have occurred, how many types of colonies exist in the culture medium? In other words, find the number of distinct values that appear as sizes of existing colonies.

Constraints

  • 1 \leq K \leq 10^{18}
  • K is an integer

Input

K
  • The first line contains an integer K representing the number of growths.

Output

Output the number of types of colonies (the number of distinct sizes) after K growths in a single line.


Sample Input 1

2

Sample Output 1

3

Sample Input 2

10

Sample Output 2

11

Sample Input 3

1000000000000000000

Sample Output 3

1000000000000000001
B - Exam Passers

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233

問題文

高橋君は学校の先生であり、期末試験の結果を集計しています。

この試験では、得点が L 点以上 R 点以下の生徒のみが合格となります。得点が低すぎる生徒はもちろん、得点が高すぎる生徒も不正の疑いがあるため、合格とはなりません。

今回の試験には N 人の生徒が受験しており、 i 番目の生徒の得点は P_i 点です。

高橋君は、合格者の中で最も得点が高い生徒の出席番号を知りたいと思っています。

合格した生徒のうち、得点が最大となる生徒の出席番号を求めてください。そのような生徒が複数いる場合は、出席番号が最も小さい生徒の番号を出力してください。ただし、合格者が一人もいない場合は -1 を出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq L \leq R \leq 100
  • 0 \leq P_i \leq 100 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N L R
P_1 P_2 \ldots P_N
  • 1 行目には、生徒の人数を表す N 、合格となる得点の下限を表す L 、上限を表す R が、スペース区切りで与えられる。
  • 2 行目には、各生徒の得点を表す P_1, P_2, \ldots, P_N が、スペース区切りで与えられる。

出力

合格した生徒のうち、得点が最大となる生徒の出席番号を 1 行で出力してください。そのような生徒が存在しない場合は -1 を出力してください。


入力例 1

5 60 80
55 72 80 90 65

出力例 1

3

入力例 2

8 50 70
45 70 60 70 80 55 30 68

出力例 2

2

入力例 3

10 40 60
35 100 25 55 60 60 75 42 38 90

出力例 3

5

Score : 233 pts

Problem Statement

Takahashi is a school teacher who is tallying the results of the final exam.

In this exam, only students who scored at least L points and at most R points will pass. Students who scored too low will not pass, and students who scored too high are also suspected of cheating, so they will not pass either.

N students took this exam, and the i-th student scored P_i points.

Takahashi wants to know the student ID of the student with the highest score among those who passed.

Find the student ID of the student with the maximum score among the students who passed. If there are multiple such students, output the student ID of the one with the smallest student ID. However, if no students passed, output -1.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq L \leq R \leq 100
  • 0 \leq P_i \leq 100 (1 \leq i \leq N)
  • All inputs are integers

Input

N L R
P_1 P_2 \ldots P_N
  • The first line contains N representing the number of students, L representing the lower bound of passing scores, and R representing the upper bound, separated by spaces.
  • The second line contains P_1, P_2, \ldots, P_N representing each student's score, separated by spaces.

Output

Output the student ID of the student with the maximum score among the students who passed, on a single line. If no such student exists, output -1.


Sample Input 1

5 60 80
55 72 80 90 65

Sample Output 1

3

Sample Input 2

8 50 70
45 70 60 70 80 55 30 68

Sample Output 2

2

Sample Input 3

10 40 60
35 100 25 55 60 60 75 42 38 90

Sample Output 3

5
C - Discount Coupon

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君はオンラインショッピングサイトで買い物をしようとしています。

ショッピングサイトには N 個の商品があり、それぞれの商品 i には価格 D_i 円が設定されています。高橋君はすべての商品を購入する予定です。

高橋君は特別な割引クーポンを持っています。このクーポンを使うと、選んだ商品の価格を 0 円にすることができます。ただし、クーポンを適用できる商品の数は最大 K 個までという制限があります。

高橋君は、クーポンを最適に使って、支払う合計金額を最小化したいと考えています。最適にクーポンを使ったとき、支払う合計金額の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq N
  • 1 \leq D_i \leq 10^9
  • 入力はすべて整数

入力

N K
D_1 D_2 \ldots D_N
  • 1 行目には、商品の数を表す N 、クーポンを適用できる最大個数を表す K が、スペース区切りで与えられる。
  • 2 行目には、各商品の価格を表す D_1, D_2, \ldots, D_N が、スペース区切りで与えられる。

出力

支払う合計金額の最小値を 1 行で出力せよ。


入力例 1

5 2
100 250 300 150 200

出力例 1

450

入力例 2

7 3
500 1200 800 300 950 1100 450

出力例 2

2050

入力例 3

10 4
1000000000 999999999 500000000 750000000 250000000 800000000 600000000 400000000 350000000 900000000

出力例 3

2850000000

Score : 300 pts

Problem Statement

Takahashi is about to go shopping on an online shopping site.

The shopping site has N items, and each item i has a price of D_i yen. Takahashi plans to purchase all the items.

Takahashi has a special discount coupon. By using this coupon, he can reduce the price of selected items to 0 yen. However, there is a restriction that the coupon can be applied to at most K items.

Takahashi wants to use the coupon optimally to minimize the total amount he pays. Find the minimum total amount he needs to pay when using the coupon optimally.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq N
  • 1 \leq D_i \leq 10^9
  • All inputs are integers

Input

N K
D_1 D_2 \ldots D_N
  • The first line contains N, representing the number of items, and K, representing the maximum number of items the coupon can be applied to, separated by a space.
  • The second line contains D_1, D_2, \ldots, D_N, representing the price of each item, separated by spaces.

Output

Output the minimum total amount to pay in one line.


Sample Input 1

5 2
100 250 300 150 200

Sample Output 1

450

Sample Input 2

7 3
500 1200 800 300 950 1100 450

Sample Output 2

2050

Sample Input 3

10 4
1000000000 999999999 500000000 750000000 250000000 800000000 600000000 400000000 350000000 900000000

Sample Output 3

2850000000
D - Merchant on the Highway

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は東西に伸びる街道沿いで商売をしている商人です。この街道には N 個の町が一列に並んでおり、西から順に 1 番目、 2 番目、...、 N 番目と番号が付けられています。 i 番目の町で商売をすると A_i の利益が得られますが、滞在費として B_i 円かかります。

高橋君は、これらの町の中からいくつかを選んで商売をすることにしました。ただし、高橋君の馬車には以下の制限があります。

  • 訪れる町は、番号が連続している必要はないが、訪れる町の番号を小さい順に並べたとき、隣り合う番号の差がすべて K 以下でなければならない。つまり、訪れる町の番号を小さい順に p_1, p_2, \ldots, p_m としたとき、すべての 1 \leq j \leq m - 1 について p_{j+1} - p_j \leq K が成り立つ必要がある。これは、馬車が一度に移動できる距離に限界があるためである。

高橋君が用意できる滞在費の総額は M 円です。訪れる町の滞在費の合計が M 円以下となるように町を選ぶとき、得られる利益の合計の最大値を求めてください。

なお、どの町も訪れない場合、利益の合計は 0 とします。

制約

  • 1 \leq N \leq 200
  • 1 \leq M \leq 200
  • 1 \leq K \leq N
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq M
  • 入力はすべて整数

入力

N M K
A_1 B_1
A_2 B_2
:
A_N B_N
  • 1 行目には、町の数を表す N 、用意できる滞在費の総額を表す M 、一度に移動できる町の数の上限を表す K が、スペース区切りで与えられる。
  • 2 行目から N + 1 行目では、各町の情報が与えられる。
  • 1 + i 行目では、 i 番目の町で得られる利益 A_i と滞在費 B_i が、スペース区切りで与えられる。

出力

条件を満たすように町を選んだとき、得られる利益の合計の最大値を 1 行で出力せよ。


入力例 1

5 10 2
8 3
5 4
10 5
3 2
7 3

出力例 1

21

入力例 2

4 5 1
100 2
200 3
150 2
50 1

出力例 2

350

入力例 3

10 50 3
1000000000 10
500000000 8
800000000 12
300000000 5
600000000 15
900000000 20
400000000 7
700000000 11
200000000 6
550000000 9

出力例 3

3450000000

Score : 400 pts

Problem Statement

Takahashi is a merchant doing business along a highway that extends from east to west. There are N towns lined up in a row along this highway, numbered 1, 2, ..., N from west to east. Doing business in the i-th town yields a profit of A_i, but costs B_i yen as accommodation expenses.

Takahashi has decided to select some of these towns to do business in. However, Takahashi's carriage has the following restriction:

  • The towns visited do not need to have consecutive numbers, but when the visited town numbers are arranged in ascending order, the difference between any two adjacent numbers must be at most K. In other words, if the visited town numbers in ascending order are p_1, p_2, \ldots, p_m, then p_{j+1} - p_j \leq K must hold for all 1 \leq j \leq m - 1. This is because the carriage has a limit on the distance it can travel at once.

The total accommodation expenses Takahashi can prepare is M yen. When selecting towns such that the total accommodation expenses of visited towns is at most M yen, find the maximum possible total profit.

Note that if no town is visited, the total profit is 0.

Constraints

  • 1 \leq N \leq 200
  • 1 \leq M \leq 200
  • 1 \leq K \leq N
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq M
  • All inputs are integers

Input

N M K
A_1 B_1
A_2 B_2
:
A_N B_N
  • The first line contains N representing the number of towns, M representing the total accommodation expenses available, and K representing the maximum number of towns that can be traveled at once, separated by spaces.
  • From the 2nd line to the (N + 1)-th line, information about each town is given.
  • The (1 + i)-th line contains the profit A_i obtainable in the i-th town and the accommodation expense B_i, separated by spaces.

Output

Output in one line the maximum possible total profit when selecting towns that satisfy the conditions.


Sample Input 1

5 10 2
8 3
5 4
10 5
3 2
7 3

Sample Output 1

21

Sample Input 2

4 5 1
100 2
200 3
150 2
50 1

Sample Output 2

350

Sample Input 3

10 50 3
1000000000 10
500000000 8
800000000 12
300000000 5
600000000 15
900000000 20
400000000 7
700000000 11
200000000 6
550000000 9

Sample Output 3

3450000000
E - Temperature Fluctuation Range

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 466

問題文

高橋君は気象データの分析をしています。ある地域で N 日間連続して気温を観測した記録があり、 i 日目の気温は H_i 度でした。

高橋君は、この観測データから連続する K 日間を選び、その期間の気温の変動幅を調べたいと考えています。

ここで、連続する K 日間の「気温の変動幅」とは、その期間における最高気温と最低気温の差として定義されます。

高橋君は、気温の変動幅が最大となるような連続する K 日間を見つけたいと考えています。気温の変動幅の最大値を求めてください。

制約

  • 1 \leq K \leq N \leq 2 \times 10^5
  • -10^9 \leq H_i \leq 10^9
  • 入力はすべて整数

入力

N K
H_1 H_2 \ldots H_N
  • 1 行目には、観測日数を表す N と、選ぶ連続した日数を表す K が、スペース区切りで与えられる。
  • 2 行目には、各日の気温を表す H_1, H_2, \ldots, H_N が、スペース区切りで与えられる。

出力

気温の変動幅の最大値を 1 行で出力してください。


入力例 1

5 3
2 5 1 8 4

出力例 1

7

入力例 2

7 4
-3 10 5 -2 8 1 6

出力例 2

13

入力例 3

12 5
100 -50 200 150 -100 300 50 -200 250 0 -150 400

出力例 3

600

Score : 466 pts

Problem Statement

Takahashi is analyzing weather data. There is a record of temperature observations taken over N consecutive days in a certain region, where the temperature on day i was H_i degrees.

Takahashi wants to select a consecutive period of K days from this observation data and investigate the temperature variation range during that period.

Here, the "temperature variation range" for a consecutive period of K days is defined as the difference between the maximum temperature and the minimum temperature during that period.

Takahashi wants to find a consecutive period of K days that maximizes the temperature variation range. Find the maximum value of the temperature variation range.

Constraints

  • 1 \leq K \leq N \leq 2 \times 10^5
  • -10^9 \leq H_i \leq 10^9
  • All inputs are integers

Input

N K
H_1 H_2 \ldots H_N
  • The first line contains N, representing the number of observation days, and K, representing the number of consecutive days to select, separated by a space.
  • The second line contains H_1, H_2, \ldots, H_N, representing the temperature on each day, separated by spaces.

Output

Output the maximum value of the temperature variation range in one line.


Sample Input 1

5 3
2 5 1 8 4

Sample Output 1

7

Sample Input 2

7 4
-3 10 5 -2 8 1 6

Sample Output 2

13

Sample Input 3

12 5
100 -50 200 150 -100 300 50 -200 250 0 -150 400

Sample Output 3

600