Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は N 件の資料を印刷します。 i 件目の資料は A_i ページあり、用紙 1 枚に B_i ページずつまとめて印刷します。最後の 1 枚は B_i ページに満たなくてもかまいません。
各資料について、必要な用紙の枚数を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq A_i \leq 1000
- 1 \leq B_i \leq 1000
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 A_2 B_2 \vdots A_N B_N
- 1 行目には、資料の件数 N が与えられる。
- 2 行目から N 行にわたり、 1 + i 行目には i 件目の資料のページ数 A_i と用紙 1 枚あたりのページ数 B_i がスペース区切りで与えられる。
出力
N 行出力せよ。 i 行目には i 件目の資料に必要な用紙の枚数を出力せよ。
入力例 1
3 7 2 10 5 5 3
出力例 1
4 2 2
入力例 2
1 1 1
出力例 2
1
入力例 3
2 9 2 3 2
出力例 3
5 2
入力例 4
2 9 2 1 2
出力例 4
5 1
入力例 5
3 7 2 10 5 6 3
出力例 5
4 2 2
Score : 200 pts
Problem Statement
Takahashi will print N documents. The i-th document has A_i pages, and he prints B_i pages per sheet of paper. The last sheet may contain fewer than B_i pages.
For each document, find the number of sheets needed.
Constraints
- 1 \leq N \leq 100
- 1 \leq A_i \leq 1000
- 1 \leq B_i \leq 1000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 A_2 B_2 \vdots A_N B_N
- The first line contains the number of documents N.
- For each of the N lines starting from the second line, the (1 + i)-th line contains the number of pages A_i of the i-th document and the number of pages per sheet B_i, separated by a space.
Output
Print N lines. The i-th line should contain the number of sheets needed for the i-th document.
Sample Input 1
3 7 2 10 5 5 3
Sample Output 1
4 2 2
Sample Input 2
1 1 1
Sample Output 2
1
Sample Input 3
2 9 2 3 2
Sample Output 3
5 2
Sample Input 4
2 9 2 1 2
Sample Output 4
5 1
Sample Input 5
3 7 2 10 5 6 3
Sample Output 5
4 2 2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君の庭は横一列に並んだ N 個のマスからなり、左から i 番目のマスの様子は文字列 S の i 文字目で表されます。 # はそのマスにモグラの穴があることを、 . は穴がないことを表します。
穴のあるマスが連続している部分のうち、最も長いものの長さを求めてください。穴が 1 つもない場合は 0 を出力してください。
制約
- 1 \leq N \leq 100
- S は
#と.のみからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
- 1 行目には、マスの個数 N が与えられる。
- 2 行目には、庭の様子を表す文字列 S が与えられる。
出力
穴のあるマスが連続している部分のうち最も長いものの長さを 1 行で出力せよ。
入力例 1
8 .##.###.
出力例 1
3
入力例 2
5 .....
出力例 2
0
入力例 3
3 #.#
出力例 3
1
入力例 4
45 #.###.#.###.###.#.######.##..##.#..###..##.##
出力例 4
6
入力例 5
15 .##..########.#
出力例 5
8
Score : 233 pts
Problem Statement
Takahashi's garden consists of N squares arranged in a row. The state of the i-th square from the left is represented by the i-th character of a string S. # means that the square has a mole hole, and . means that it does not.
Find the length of the longest contiguous segment of squares that have holes. If there are no holes at all, print 0.
Constraints
- 1 \leq N \leq 100
- S is a string of length N consisting of
#and.
Input
The input is given from standard input in the following format:
N S
- The first line contains the number of squares N.
- The second line contains the string S representing the state of the garden.
Output
Print the length of the longest contiguous segment of squares with holes in one line.
Sample Input 1
8 .##.###.
Sample Output 1
3
Sample Input 2
5 .....
Sample Output 2
0
Sample Input 3
3 #.#
Sample Output 3
1
Sample Input 4
45 #.###.#.###.###.#.######.##..##.#..###..##.##
Sample Output 4
6
Sample Input 5
15 .##..########.#
Sample Output 5
8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
遊園地に、N 個のゴンドラが円形に並んだ観覧車があります。ゴンドラには 1 から N まで番号が付けられており、ゴンドラ i(1 \leq i \leq N)の美しさは A_i です。ゴンドラは円形に並んでいるため、ゴンドラ N の次はゴンドラ 1 です。
この観覧車の乗り場からは、円周上で連続するちょうど M 個のゴンドラが見えます。観覧車は任意の位置まで回転させることができるので、見えるゴンドラの組を自由に選べます。
観覧車を最適な位置まで回転させたとき、乗り場から見える M 個のゴンドラの美しさの合計の最大値を求めてください。
制約
- 1 \leq M \leq N \leq 5 \times 10^5
- -10^9 \leq A_i \leq 10^9
- 入力はすべて整数である
入力
N M A_1 A_2 \ldots A_N
- 1 行目には、ゴンドラの個数 N と、乗り場から見える連続したゴンドラの個数 M が、スペース区切りで与えられる。
- 2 行目には、各ゴンドラの美しさ A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
乗り場から見える連続する M 個のゴンドラの美しさの合計の最大値を 1 行で出力せよ。
入力例 1
5 3 1 2 3 4 5
出力例 1
12
入力例 2
4 2 -5 -2 -3 -4
出力例 2
-5
入力例 3
12 5 8 -3 6 1 -2 4 7 -5 9 -1 3 2
出力例 3
21
入力例 4
20 7 5 -8 12 7 -3 9 -10 4 6 -2 11 -5 13 -7 8 1 -4 10 -6 14
出力例 4
36
入力例 5
1 1 -1000000000
出力例 5
-1000000000
Score : 300 pts
Problem Statement
At an amusement park, there is a Ferris wheel with N gondolas arranged in a circle. The gondolas are numbered from 1 to N, and the beauty of gondola i (1 \leq i \leq N) is A_i. Since the gondolas are arranged in a circle, gondola 1 comes after gondola N.
From the boarding platform, exactly M consecutive gondolas along the circumference are visible. Since the Ferris wheel can be rotated to any position, you can freely choose which set of gondolas is visible.
When the Ferris wheel is rotated to the optimal position, find the maximum possible sum of the beauty values of the M gondolas visible from the boarding platform.
Constraints
- 1 \leq M \leq N \leq 5 \times 10^5
- -10^9 \leq A_i \leq 10^9
- All input values are integers.
Input
N M A_1 A_2 \ldots A_N
- The first line contains the number of gondolas N and the number of consecutive gondolas visible from the boarding platform M, separated by a space.
- The second line contains the beauty values of each gondola A_1, A_2, \ldots, A_N, separated by spaces.
Output
Print the maximum possible sum of the beauty values of M consecutive gondolas visible from the boarding platform, on a single line.
Sample Input 1
5 3 1 2 3 4 5
Sample Output 1
12
Sample Input 2
4 2 -5 -2 -3 -4
Sample Output 2
-5
Sample Input 3
12 5 8 -3 6 1 -2 4 7 -5 9 -1 3 2
Sample Output 3
21
Sample Input 4
20 7 5 -8 12 7 -3 9 -10 4 6 -2 11 -5 13 -7 8 1 -4 10 -6 14
Sample Output 4
36
Sample Input 5
1 1 -1000000000
Sample Output 5
-1000000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君はあるゲームをプレイしています。このゲームにはステージ 1 からステージ N までの N 個のステージがあります。
高橋君は、各ステージについてそれぞれクリアするかどうかを自由に選ぶことができます(1 つもステージをクリアしなくても構いません)。
ゲーム開始時のスコアは 0 であり、最終的なスコアはクリアしたステージに応じて以下のように計算されます。
- ステージ i (1 \le i \le N) をクリアした場合、スコアに A_i が加算される(A_i が負の値の場合はスコアが減少します)。
- 各 i (1 \le i \le N - 1) について、ステージ i とステージ i + 1 の両方をクリアした場合、コンボボーナスとしてスコアにさらに C が加算される(例えば、ステージ 1, 2, 3 をすべてクリアした場合、ペア (1, 2) とペア (2, 3) に対してそれぞれボーナスが発生し、計 2C が加算されます)。
高橋君が適切にクリアするステージを選択したとき、獲得できる最終スコアの最大値を求めてください。
制約
- 1 \le N \le 10^6
- 0 \le C \le 10^9
- -10^9 \le A_i \le 10^9 (1 \le i \le N)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N C A_1 A_2 \dots A_N
出力
高橋君が獲得できる最終スコアの最大値を 1 行で出力してください。
入力例 1
4 3 5 -4 6 -10
出力例 1
13
入力例 2
3 2 -5 -3 -4
出力例 2
0
入力例 3
12 10 -3 8 12 -15 7 0 -4 19 22 -30 15 -1
出力例 3
150
入力例 4
30 100 10 -20 30 -40 50 -60 70 -80 90 -100 110 -120 130 -140 150 -160 170 -180 190 -200 210 -220 230 -240 250 -260 270 -280 290 -300
出力例 4
3150
入力例 5
1 1000000000 -1000000000
出力例 5
0
Score : 366 pts
Problem Statement
Takahashi is playing a game. This game has N stages, numbered Stage 1 through Stage N.
For each stage, Takahashi can freely choose whether to clear it or not (he may choose not to clear any stages at all).
The score at the start of the game is 0, and the final score is calculated based on the cleared stages as follows:
- If he clears Stage i (1 \le i \le N), A_i is added to the score (if A_i is negative, the score decreases).
- For each i (1 \le i \le N - 1), if he clears both Stage i and Stage i + 1, an additional C is added to the score as a combo bonus (for example, if he clears all of Stages 1, 2, 3, a bonus is granted for each of the pairs (1, 2) and (2, 3), adding a total of 2C).
Find the maximum possible final score Takahashi can obtain by optimally choosing which stages to clear.
Constraints
- 1 \le N \le 10^6
- 0 \le C \le 10^9
- -10^9 \le A_i \le 10^9 (1 \le i \le N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N C A_1 A_2 \dots A_N
Output
Print the maximum possible final score Takahashi can obtain in a single line.
Sample Input 1
4 3 5 -4 6 -10
Sample Output 1
13
Sample Input 2
3 2 -5 -3 -4
Sample Output 2
0
Sample Input 3
12 10 -3 8 12 -15 7 0 -4 19 22 -30 15 -1
Sample Output 3
150
Sample Input 4
30 100 10 -20 30 -40 50 -60 70 -80 90 -100 110 -120 130 -140 150 -160 170 -180 190 -200 210 -220 230 -240 250 -260 270 -280 290 -300
Sample Output 4
3150
Sample Input 5
1 1000000000 -1000000000
Sample Output 5
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
高橋君は、商店街に並ぶ N 軒の店舗の売上を管理しています。店舗は左から順に 1 番から N 番まで番号が付けられており、店舗 i の初期の月間売上は V_i 円です。はじめ、すべての店舗は営業中です。
高橋君は Q 回の操作を順番に行います。各操作は以下の 3 種類のいずれかです。
- 操作 1(
1 l r x):季節キャンペーンにより、店舗 l 番から r 番までの営業中のすべての店舗の売上を x 円だけ増加させる。この範囲に閉店済みの店舗が含まれていても、その店舗の売上は変化しない。
- 操作 2(
2 p):店舗 p 番が閉店する。閉店した店舗の売上はその時点での値で確定する(操作 2 自体は売上の値を変化させない)。閉店した店舗は、以降の操作 1 による売上増加の影響を受けない。なお、店舗 p はこの操作の時点で営業中であることが保証される。
- 操作 3(
3 k):以下の手順で値を求め、出力する。
- 現在営業中の店舗を番号の小さい順に並べたとき、k 番目の店舗の番号を j とする。
- 店舗 1 番から店舗 j 番までの中で、既に閉店している店舗をすべて集める。
- それらの閉店済み店舗それぞれについて、閉店した時点での売上(操作 2 が行われた時点の売上)を求め、その合計を出力する。該当する閉店済み店舗が 1 つもない場合は 0 を出力する。
この合計値を「累積閉店売上額」と呼ぶ。
制約
- 1 \leq N \leq 10^5
- 1 \leq Q \leq 10^5
- 0 \leq V_i \leq 10^9(1 \leq i \leq N)
- 操作 1 において、1 \leq l \leq r \leq N、1 \leq x \leq 10^4
- 操作 2 において、1 \leq p \leq N、かつ店舗 p はその時点で営業中である
- 操作 3 において、1 \leq k \leq (その時点で営業中の店舗の数)(特に、操作 3 が与えられる時点で営業中の店舗が 1 つ以上存在する)
- 入力はすべて整数である
- 出力すべき値は 2^{63} 未満であることが保証される(64 ビット符号付き整数に収まる)
入力
N Q
V_1 V_2 \ldots V_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
- 1 行目には、店舗の数 N と操作の回数 Q がスペース区切りで与えられる。
- 2 行目には、各店舗の初期売上 V_1, V_2, \ldots, V_N がスペース区切りで与えられる。
- 3 行目から Q 行にわたって、各操作が 1 行ずつ与えられる。各操作は以下の形式である。
- 操作 1 の場合:
1 l r x(店舗 l 番から r 番の営業中の店舗の売上を x 円増加させる) - 操作 2 の場合:
2 p(店舗 p 番を閉店させる) - 操作 3 の場合:
3 k(営業中の店舗のうち左から k 番目の店舗の番号 j を求め、店舗 1 番から j 番までの累積閉店売上額を出力する)
出力
操作 3 が与えられるたびに、対応する累積閉店売上額を 1 行に出力せよ。
入力例 1
5 9 10 20 30 40 50 3 1 1 2 4 5 2 3 3 2 1 1 5 10 2 2 3 2 2 1 3 1
出力例 1
0 0 70 90
入力例 2
4 7 0 5 10 15 1 1 4 3 2 1 3 1 2 4 1 2 4 2 3 2 3 1
出力例 2
3 3 3
入力例 3
10 18 100 200 300 400 500 600 700 800 900 1000 1 1 5 10 2 4 3 4 1 3 8 20 2 7 3 6 2 1 1 1 10 5 3 1 2 5 3 3 1 6 10 100 2 10 3 5 2 2 3 1 1 1 10 1 3 4
出力例 3
410 1130 110 1055 1775 325 1990
入力例 4
20 35 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 1 1 20 100 2 10 2 1 3 1 1 5 15 50 2 7 3 6 1 1 8 10 2 8 3 5 2 20 1 10 20 200 3 12 2 15 3 10 1 1 20 1 2 2 2 3 3 1 1 4 12 30 2 12 3 7 2 4 2 5 3 1 1 1 20 9999 2 19 3 8 2 6 3 1 2 9 2 11 3 3 1 13 18 123 3 5
出力例 4
105 290 105 640 640 352 1328 729 2130 11334 33010 33010
入力例 5
1 4 1000000000 3 1 1 1 1 10000 3 1 2 1
出力例 5
0 0
Score : 466 pts
Problem Statement
Takahashi manages the sales of N stores lined up in a shopping street. The stores are numbered from 1 to N from left to right, and the initial monthly sales of store i is V_i yen. Initially, all stores are open.
Takahashi performs Q operations in order. Each operation is one of the following 3 types:
- Operation 1 (
1 l r x): Due to a seasonal campaign, increase the sales of all open stores from store l to store r by x yen. Even if closed stores are included in this range, their sales do not change.
- Operation 2 (
2 p): Store p closes. The sales of a closed store are finalized at the value at that point in time (Operation 2 itself does not change the sales value). A closed store is not affected by sales increases from subsequent Operation 1s. It is guaranteed that store p is open at the time of this operation.
- Operation 3 (
3 k): Determine and output a value according to the following procedure:
- When the currently open stores are listed in increasing order of their numbers, let j be the number of the k-th store.
- Among stores from store 1 to store j, collect all stores that have already closed.
- For each of those closed stores, determine the sales at the time of closure (the sales at the time Operation 2 was performed on it), and output the total. If there are no such closed stores, output 0.
This total is called the "cumulative closed sales amount."
Constraints
- 1 \leq N \leq 10^5
- 1 \leq Q \leq 10^5
- 0 \leq V_i \leq 10^9 (1 \leq i \leq N)
- For Operation 1: 1 \leq l \leq r \leq N, 1 \leq x \leq 10^4
- For Operation 2: 1 \leq p \leq N, and store p is open at that time
- For Operation 3: 1 \leq k \leq (the number of currently open stores) (in particular, at least one store is open when Operation 3 is given)
- All input values are integers
- It is guaranteed that the values to be output are less than 2^{63} (they fit in a 64-bit signed integer)
Input
N Q
V_1 V_2 \ldots V_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
- The first line contains the number of stores N and the number of operations Q, separated by a space.
- The second line contains the initial sales V_1, V_2, \ldots, V_N of each store, separated by spaces.
- The following Q lines each contain one operation. Each operation is in the following format:
- For Operation 1:
1 l r x(increase the sales of open stores from store l to store r by x yen) - For Operation 2:
2 p(close store p) - For Operation 3:
3 k(find the number j of the k-th store among open stores from the left, and output the cumulative closed sales amount from store 1 to store j)
Output
Each time Operation 3 is given, output the corresponding cumulative closed sales amount on one line.
Sample Input 1
5 9 10 20 30 40 50 3 1 1 2 4 5 2 3 3 2 1 1 5 10 2 2 3 2 2 1 3 1
Sample Output 1
0 0 70 90
Sample Input 2
4 7 0 5 10 15 1 1 4 3 2 1 3 1 2 4 1 2 4 2 3 2 3 1
Sample Output 2
3 3 3
Sample Input 3
10 18 100 200 300 400 500 600 700 800 900 1000 1 1 5 10 2 4 3 4 1 3 8 20 2 7 3 6 2 1 1 1 10 5 3 1 2 5 3 3 1 6 10 100 2 10 3 5 2 2 3 1 1 1 10 1 3 4
Sample Output 3
410 1130 110 1055 1775 325 1990
Sample Input 4
20 35 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 1 1 20 100 2 10 2 1 3 1 1 5 15 50 2 7 3 6 1 1 8 10 2 8 3 5 2 20 1 10 20 200 3 12 2 15 3 10 1 1 20 1 2 2 2 3 3 1 1 4 12 30 2 12 3 7 2 4 2 5 3 1 1 1 20 9999 2 19 3 8 2 6 3 1 2 9 2 11 3 3 1 13 18 123 3 5
Sample Output 4
105 290 105 640 640 352 1328 729 2130 11334 33010 33010
Sample Input 5
1 4 1000000000 3 1 1 1 1 10000 3 1 2 1
Sample Output 5
0 0