A - Passing Score

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は学校の期末テストの結果を集計しています。

このクラスには N 人の生徒がおり、生徒 i の得点は A_i 点です。得点はすべて 0 点以上 100 点以下の整数です。

先生は合格ラインとして X 点を設定しました。得点が X 点以上の生徒は合格、X 点未満の生徒は不合格となり、補習を受けなければなりません。

補習を受けなければならない生徒、すなわち得点が X 点未満の生徒の人数を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq X \leq 100
  • 0 \leq A_i \leq 100
  • 入力はすべて整数

入力

N X
A_1 A_2 \ldots A_N
  • 1 行目には、生徒の人数を表す整数 N と、合格ラインを表す整数 X が、スペース区切りで与えられる。
  • 2 行目には、各生徒の得点を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
  • A_i は生徒 i の得点を表す。

出力

得点が X 点未満の生徒の人数を 1 行で出力せよ。


入力例 1

5 60
72 45 60 38 85

出力例 1

2

入力例 2

8 50
49 50 51 30 75 50 48 100

出力例 2

3

入力例 3

15 70
65 70 82 55 91 68 70 43 77 69 100 35 88 71 60

出力例 3

7

Score : 200 pts

Problem Statement

Takahashi is tallying the results of his school's final exam.

There are N students in the class, and student i scored A_i points. All scores are integers between 0 and 100, inclusive.

The teacher has set a passing grade of X points. Students who scored X points or more pass, while students who scored less than X points fail and must attend supplementary lessons.

Find the number of students who must attend supplementary lessons, that is, the number of students who scored less than X points.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq X \leq 100
  • 0 \leq A_i \leq 100
  • All inputs are integers

Input

N X
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of students and an integer X representing the passing grade, separated by a space.
  • The second line contains integers A_1, A_2, \ldots, A_N representing each student's score, separated by spaces.
  • A_i represents the score of student i.

Output

Print the number of students who scored less than X points, on a single line.


Sample Input 1

5 60
72 45 60 38 85

Sample Output 1

2

Sample Input 2

8 50
49 50 51 30 75 50 48 100

Sample Output 2

3

Sample Input 3

15 70
65 70 82 55 91 68 70 43 77 69 100 35 88 71 60

Sample Output 3

7
B - Warehouse Inspection Robot

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 266

問題文

高橋君は HW 列のグリッド状の倉庫を管理しています。上から i 行目 (1 \leq i \leq H)、左から j 列目 (1 \leq j \leq W) のマスをマス (i, j) と表します。各マスには荷物が置かれているか、何もないかのどちらかです。倉庫の状態は H 個の長さ W の文字列 S_1, S_2, \ldots, S_H で表され、S_ij 文字目が # ならマス (i, j) に荷物が置かれており、. なら何もないことを意味します。

高橋君はこの倉庫に点検ロボットを 1 台導入し、ロボットを動かすことで荷物の回収をしようと考えています。ロボットは最初、マス (1, 1)(左上隅)に配置されます。

ロボットには長さ N の文字列 T で表される N 個の命令が順番に与えられます。Tk 文字目 (1 \leq k \leq N)k 番目の命令に対応し、各命令は以下のいずれかです。

  • U:上に 1 マス移動する(行番号が 1 減る方向)
  • D:下に 1 マス移動する(行番号が 1 増える方向)
  • L:左に 1 マス移動する(列番号が 1 減る方向)
  • R:右に 1 マス移動する(列番号が 1 増える方向)

ただし、命令による移動先がグリッドの外になる場合、その命令は無視され、ロボットはその場に留まります。

ロボットの動作は以下の流れで処理されます。

  1. ロボットがマス (1, 1) に配置される。マス (1, 1) に荷物があれば、回収される(そのマスの荷物がなくなる)。
  2. k = 1, 2, \ldots, N の順に、k 番目の命令を実行する。各命令の処理後(移動した場合も、命令が無視されてその場に留まった場合も)、ロボットがいるマスに荷物があれば、回収される(そのマスの荷物がなくなる)。

すでに荷物が回収されたマスを再び訪れても何も起きません。

すべての命令を実行し終えた後、倉庫に残っている荷物の個数を求めてください。

制約

  • 1 \leq H \leq 500
  • 1 \leq W \leq 500
  • 1 \leq N \leq 2 \times 10^5
  • H, W, N は整数
  • S_i は長さ W の文字列で、#. のみからなる
  • T は長さ N の文字列で、U, D, L, R のみからなる

入力

H W N
S_1
S_2
\vdots
S_H
T
  • 1 行目には、倉庫の行数 H、列数 W、命令の数 N が、スペース区切りで与えられます。
  • 2 行目から H + 1 行目には、倉庫の状態を表す文字列 S_i (1 \leq i \leq H) が与えられます。
  • S_i は長さ W の文字列で、j 文字目が # ならマス (i, j) に荷物が置かれており、. なら何もないことを表します。
  • H + 2 行目には、ロボットへの命令を表す長さ N の文字列 T が与えられます。
  • TU, D, L, R のみからなります。

出力

すべての命令を実行し終えた後に倉庫に残っている荷物の個数を 1 行で出力してください。


入力例 1

3 4 9
#..#
.##.
..#.
RRDDLUUUL

出力例 1

1

入力例 2

2 3 8
###
..#
UUURRRDD

出力例 2

0

入力例 3

6 7 30
.#..#..
##...#.
..#.#..
.##....
...###.
#..#..#
RRRDDRULDLURRRDDLLUUURRDDDLURD

出力例 3

10

入力例 4

12 15 60
#..#...##....#.
.#....#....##..
....##..#...#..
###...#..#.....
..#..#..##..#..
.....#.....#..#
.##..#..#..##..
...#.....##....
#....###...#...
..##..#....#..#
.#...#..#..#...
...#..##.....#.
RRDDLLUUURRRDDLLUUURRRDDLLUUURRRDDLLUUURRRDDLLUUURRRDDLLUUUR

出力例 4

46

入力例 5

1 1 12
#
UDLRUDLRUDLR

出力例 5

0

Score : 266 pts

Problem Statement

Takahashi manages a warehouse in the form of a grid with H rows and W columns. The cell at the i-th row from the top (1 \leq i \leq H) and the j-th column from the left (1 \leq j \leq W) is denoted as cell (i, j). Each cell either has a package placed on it or is empty. The state of the warehouse is represented by H strings S_1, S_2, \ldots, S_H, each of length W. If the j-th character of S_i is #, then cell (i, j) has a package; if it is ., the cell is empty.

Takahashi plans to introduce one inspection robot into this warehouse and have it collect packages by moving around. The robot is initially placed at cell (1, 1) (the top-left corner).

The robot is given N instructions in order, represented by a string T of length N. The k-th character of T (1 \leq k \leq N) corresponds to the k-th instruction, and each instruction is one of the following:

  • U: Move one cell up (row number decreases by 1)
  • D: Move one cell down (row number increases by 1)
  • L: Move one cell left (column number decreases by 1)
  • R: Move one cell right (column number increases by 1)

However, if the destination of an instruction would be outside the grid, that instruction is ignored, and the robot stays in its current position.

The robot operates as follows:

  1. The robot is placed at cell (1, 1). If cell (1, 1) has a package, it is collected (the package is removed from that cell).
  2. For k = 1, 2, \ldots, N in order, the k-th instruction is executed. After processing each instruction (whether the robot moved or the instruction was ignored and the robot stayed in place), if there is a package on the cell where the robot is located, it is collected (the package is removed from that cell).

If the robot revisits a cell from which a package has already been collected, nothing happens.

Determine the number of packages remaining in the warehouse after all instructions have been executed.

Constraints

  • 1 \leq H \leq 500
  • 1 \leq W \leq 500
  • 1 \leq N \leq 2 \times 10^5
  • H, W, N are integers
  • S_i is a string of length W consisting only of # and .
  • T is a string of length N consisting only of U, D, L, R

Input

H W N
S_1
S_2
\vdots
S_H
T
  • The first line contains the number of rows H, the number of columns W, and the number of instructions N, separated by spaces.
  • The 2-nd through (H + 1)-th lines contain the strings S_i (1 \leq i \leq H) representing the state of the warehouse.
  • S_i is a string of length W, where the j-th character being # means cell (i, j) has a package, and . means it is empty.
  • The (H + 2)-th line contains the string T of length N representing the instructions to the robot.
  • T consists only of U, D, L, R.

Output

Print the number of packages remaining in the warehouse after all instructions have been executed, on a single line.


Sample Input 1

3 4 9
#..#
.##.
..#.
RRDDLUUUL

Sample Output 1

1

Sample Input 2

2 3 8
###
..#
UUURRRDD

Sample Output 2

0

Sample Input 3

6 7 30
.#..#..
##...#.
..#.#..
.##....
...###.
#..#..#
RRRDDRULDLURRRDDLLUUURRDDDLURD

Sample Output 3

10

Sample Input 4

12 15 60
#..#...##....#.
.#....#....##..
....##..#...#..
###...#..#.....
..#..#..##..#..
.....#.....#..#
.##..#..#..##..
...#.....##....
#....###...#...
..##..#....#..#
.#...#..#..#...
...#..##.....#.
RRDDLLUUURRRDDLLUUURRRDDLLUUURRRDDLLUUURRRDDLLUUURRRDDLLUUUR

Sample Output 4

46

Sample Input 5

1 1 12
#
UDLRUDLRUDLR

Sample Output 5

0
C - Air Conditioning Installation in Classrooms

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君は学校の設備管理を担当しています。学校には N 個の教室があり、それぞれの教室 i1 \leq i \leq N)には古いエアコンが 1 台設置されています。各教室のエアコンには老朽度 D_i が定められており、老朽度が高いほどエアコンが古く性能が悪いことを意味します。

今回、新しいエアコンが M 台届きました。高橋君は、N 個の教室の中から 0 個以上 M 個以下の相異なる教室を選び、選んだ各教室の古いエアコンを新しいエアコン 1 台と交換することができます。各教室に対して交換できるのは最大 1 回であり、届いた M 台すべてを使い切る必要はありません。交換を行った教室の老朽度は 0 になり、交換を行わなかった教室の老朽度は元の D_i のまま変わりません。

高橋君は、交換する教室をうまく選ぶことで、交換後における全教室の老朽度の最大値をできるだけ小さくしたいと考えています。この最大値として達成可能な最小値を求めてください。

制約

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

入力

N M
D_1 D_2 \ldots D_N
  • 1 行目には、教室の数を表す整数 N と、届いた新しいエアコンの台数を表す整数 M が、空白区切りで与えられる。
  • 2 行目には、各教室の老朽度を表す整数 D_1, D_2, \ldots, D_N が、空白区切りで与えられる。

出力

交換後における全教室の老朽度の最大値として達成可能な最小値を 1 行で出力せよ。


入力例 1

5 2
3 1 4 1 5

出力例 1

3

入力例 2

7 7
10 20 30 40 50 60 70

出力例 2

0

入力例 3

10 3
100 200 300 400 500 600 700 800 900 1000000000

出力例 3

700

Score : 300 pts

Problem Statement

Takahashi is in charge of facility management at a school. The school has N classrooms, and each classroom i (1 \leq i \leq N) has one old air conditioner installed. Each classroom's air conditioner has a deterioration level D_i, where a higher deterioration level means the air conditioner is older and has worse performance.

This time, M new air conditioners have arrived. Takahashi can choose 0 or more and M or fewer distinct classrooms from the N classrooms, and replace the old air conditioner in each chosen classroom with one new air conditioner. Each classroom can be replaced at most once, and it is not necessary to use all M new air conditioners. The deterioration level of a classroom where a replacement was made becomes 0, while the deterioration level of a classroom where no replacement was made remains at its original value D_i.

Takahashi wants to choose the classrooms for replacement wisely so as to minimize the maximum deterioration level among all classrooms after the replacements. Find the minimum achievable value of this maximum.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq N
  • 0 \leq D_i \leq 10^9
  • All input values are integers

Input

N M
D_1 D_2 \ldots D_N
  • The first line contains an integer N representing the number of classrooms and an integer M representing the number of new air conditioners that arrived, separated by a space.
  • The second line contains integers D_1, D_2, \ldots, D_N representing the deterioration level of each classroom, separated by spaces.

Output

Print in one line the minimum achievable value of the maximum deterioration level among all classrooms after the replacements.


Sample Input 1

5 2
3 1 4 1 5

Sample Output 1

3

Sample Input 2

7 7
10 20 30 40 50 60 70

Sample Output 2

0

Sample Input 3

10 3
100 200 300 400 500 600 700 800 900 1000000000

Sample Output 3

700
D - Constellation Observation Tour

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は天文台で星座観測ツアーのガイドをしています。

天文台の観測デッキには N 個の望遠鏡が数直線上に設置されています。各望遠鏡には 1 から N までの番号が付けられており、望遠鏡 i は座標 X_i の位置に設置されています。どの 2 つの望遠鏡も異なる座標に設置されています。

ツアーでは、参加者は最初に望遠鏡 S の前にいます。その後、以下のルールに従って移動を Q 回繰り返します。

  • 現在いる望遠鏡を除いた N-1 個の望遠鏡のうち、現在の位置からの距離(座標の差の絶対値)が最も小さい望遠鏡へ移動する。距離が最も小さい望遠鏡が複数存在する場合は、そのうち番号が最も小さい望遠鏡へ移動する。

なお、直前にいた望遠鏡へ戻ることは禁止されていません(現在いる望遠鏡自身のみが移動先の候補から除外されます)。

Q 回の移動後に参加者がいる望遠鏡の番号を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq S \leq N
  • 1 \leq Q \leq 10^{18}
  • -10^9 \leq X_i \leq 10^9
  • X_i \neq X_ji \neq j
  • 入力はすべて整数

入力

N S Q
X_1 X_2 \cdots X_N
  • 1 行目には、望遠鏡の数を表す整数 N 、最初にいる望遠鏡の番号を表す整数 S 、移動回数を表す整数 Q が、スペース区切りで与えられる。
  • 2 行目には、各望遠鏡の座標を表す整数 X_1, X_2, \ldots, X_N が、スペース区切りで与えられる。
  • X_i は望遠鏡 i の座標を表す。

出力

Q 回の移動後に参加者がいる望遠鏡の番号を 1 行で出力せよ。


入力例 1

3 1 3
1 3 6

出力例 1

2

入力例 2

4 2 4
0 10 5 20

出力例 2

1

入力例 3

5 3 1000000000
1 4 6 9 15

出力例 3

3

入力例 4

10 5 1000000000000000000
-1000000000 -500000000 -100 0 50 100 200 500000000 999999999 1000000000

出力例 4

5

入力例 5

2 1 1000000000000000000
0 1

出力例 5

1

Score : 400 pts

Problem Statement

Takahashi is guiding a constellation observation tour at an observatory.

On the observation deck of the observatory, N telescopes are installed along a number line. Each telescope is numbered from 1 to N, and telescope i is installed at coordinate X_i. No two telescopes are installed at the same coordinate.

During the tour, participants start in front of telescope S. After that, they repeat the following movement Q times:

  • Among the N-1 telescopes excluding the one you are currently at, move to the telescope whose distance (absolute difference of coordinates) from your current position is the smallest. If there are multiple telescopes with the smallest distance, move to the one with the smallest number among them.

Note that returning to the telescope you were at immediately before is not prohibited (only the telescope you are currently at is excluded from the movement candidates).

Determine the number of the telescope where the participant is after Q moves.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq S \leq N
  • 1 \leq Q \leq 10^{18}
  • -10^9 \leq X_i \leq 10^9
  • X_i \neq X_j (i \neq j)
  • All inputs are integers

Input

N S Q
X_1 X_2 \cdots X_N
  • The first line contains an integer N representing the number of telescopes, an integer S representing the number of the starting telescope, and an integer Q representing the number of moves, separated by spaces.
  • The second line contains integers X_1, X_2, \ldots, X_N representing the coordinates of each telescope, separated by spaces.
  • X_i represents the coordinate of telescope i.

Output

Print on one line the number of the telescope where the participant is after Q moves.


Sample Input 1

3 1 3
1 3 6

Sample Output 1

2

Sample Input 2

4 2 4
0 10 5 20

Sample Output 2

1

Sample Input 3

5 3 1000000000
1 4 6 9 15

Sample Output 3

3

Sample Input 4

10 5 1000000000000000000
-1000000000 -500000000 -100 0 50 100 200 500000000 999999999 1000000000

Sample Output 4

5

Sample Input 5

2 1 1000000000000000000
0 1

Sample Output 5

1
E - Organizing the Bookshelf

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 466

問題文

高橋君の本棚には N 冊の本が横一列に並べられています。最初、左から i 番目の位置にある本の耐久値は D_i です。

高橋君はこの本棚に対して Q 回の操作を順番に行います。j 回目の操作では、整数 T_j が与えられ、以下の手順で処理されます。

  1. そのとき本棚に残っている本の冊数を M とします。
  2. T_j > M の場合、左から T_j 番目の本は存在しないため、何も起こりません。
  3. T_j \leq M の場合、そのとき本棚の左から T_j 番目にある本の耐久値を 1 減らします。耐久値が 0 になった場合、その本は直ちに本棚から取り除かれます。取り除かれた本より右にあった本は、それぞれ 1 つずつ左の位置に移動し、残った本の間に隙間が生じないようになります。

各操作の後(何も起こらなかった場合も含む)に、本棚に残っている本の冊数を出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq D_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq T_j \leq N (1 \leq j \leq Q)
  • 入力はすべて整数である。

注意: T_j は初期の冊数 N 以下ですが、操作時点での冊数 M を超える場合があります。その場合は上記の手順 2 により何も起こりません。


入力

N Q
D_1 D_2 \ldots D_N
T_1
T_2
\vdots
T_Q
  • 1 行目には、本の初期冊数を表す整数 N と、操作の回数を表す整数 Q が、スペース区切りで与えられる。
  • 2 行目には、左から i 番目の本の耐久値を表す整数 D_1, D_2, \ldots, D_N が、スペース区切りで与えられる。
  • 続く Q 行のうち j 行目 (1 \leq j \leq Q) には、j 回目の操作で対象となる位置を表す整数 T_j が与えられる。

出力

Q 行出力せよ。j 行目には、j 回目の操作の後に本棚に残っている本の冊数を出力せよ。


入力例 1

5 5
1 2 3 1 2
2
4
2
1
3

出力例 1

5
4
3
2
2

入力例 2

3 4
1 1 1
1
1
1
1

出力例 2

2
1
0
0

入力例 3

10 10
2 1 3 1 2 1 4 2 1 3
3
5
1
7
2
4
3
1
2
1

出力例 3

10
10
10
10
9
8
7
6
5
5

入力例 4

20 25
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
1
3
5
7
2
10
15
1
3
5
8
12
1
1
2
4
6
3
2
1
5
4
3
2
1

出力例 4

20
20
20
20
19
19
19
19
18
17
17
17
16
16
16
16
16
16
16
16
16
16
16
16
15

入力例 5

1 1
1000000000
1

出力例 5

1

Score : 466 pts

Problem Statement

There are N books arranged in a horizontal row on Takahashi's bookshelf. Initially, the book at the i-th position from the left has a durability of D_i.

Takahashi performs Q operations on this bookshelf in order. In the j-th operation, an integer T_j is given, and the following procedure is carried out:

  1. Let M be the number of books currently remaining on the bookshelf.
  2. If T_j > M, the T_j-th book from the left does not exist, so nothing happens.
  3. If T_j \leq M, the durability of the book currently at the T_j-th position from the left on the bookshelf is decreased by 1. If the durability becomes 0, that book is immediately removed from the bookshelf. All books that were to the right of the removed book shift one position to the left, so that no gaps remain among the remaining books.

After each operation (including cases where nothing happens), output the number of books remaining on the bookshelf.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq D_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq T_j \leq N (1 \leq j \leq Q)
  • All input values are integers.

Note: T_j is at most the initial number of books N, but it may exceed the number of books M at the time of the operation. In that case, nothing happens as described in step 2 above.


Input

N Q
D_1 D_2 \ldots D_N
T_1
T_2
\vdots
T_Q
  • The first line contains two space-separated integers: N, the initial number of books, and Q, the number of operations.
  • The second line contains N space-separated integers D_1, D_2, \ldots, D_N, where D_i represents the durability of the i-th book from the left.
  • Each of the following Q lines contains a single integer T_j (1 \leq j \leq Q), representing the target position for the j-th operation.

Output

Output Q lines. The j-th line should contain the number of books remaining on the bookshelf after the j-th operation.


Sample Input 1

5 5
1 2 3 1 2
2
4
2
1
3

Sample Output 1

5
4
3
2
2

Sample Input 2

3 4
1 1 1
1
1
1
1

Sample Output 2

2
1
0
0

Sample Input 3

10 10
2 1 3 1 2 1 4 2 1 3
3
5
1
7
2
4
3
1
2
1

Sample Output 3

10
10
10
10
9
8
7
6
5
5

Sample Input 4

20 25
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
1
3
5
7
2
10
15
1
3
5
8
12
1
1
2
4
6
3
2
1
5
4
3
2
1

Sample Output 4

20
20
20
20
19
19
19
19
18
17
17
17
16
16
16
16
16
16
16
16
16
16
16
16
15

Sample Input 5

1 1
1000000000
1

Sample Output 5

1