実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 150 点
問題文
AtCoder社のオフィスには加湿器が 1 つあります。現在は時刻 0 であり、加湿器には水が入っていません。
あなたはこの加湿器にこれから N 回水を追加します。i 回目 (1\leq i \leq N)の水の追加は時刻 T_i に行い、水を V_i リットル追加します。なお、 T_i < T_{i+1} (1 \leq i \leq N-1) を満たすことが保証されます。
ただし、加湿器には穴が空いていて、加湿器に水が入っている間は 1 単位時間につき水が 1 リットル減り続けます。
時刻 T_N に水を追加し終えたとき、加湿器に残っている水の量を求めてください。
制約
- 1 \leq N \leq 100
- 1 \leq T_i \leq 100 (1 \leq i \leq N)
- 1 \leq V_i \leq 100 (1 \leq i \leq N)
- T_i < T_{i+1} (1 \leq i \leq N-1)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N T_1 V_1 T_2 V_2 \vdots T_N V_N
出力
答えを出力せよ。
入力例 1
4 1 3 3 1 4 4 7 1
出力例 1
3
時系列で以下のように水が追加されます。
- 時刻 1 : 水を追加する前は 0 リットル入っており、3 リットル追加して加湿器には 3 リットルの水が入っています。
- 時刻 3 : 水を追加する前は 1 リットル入っており、1 リットル追加して加湿器には 2 リットルの水が入っています。
- 時刻 4 : 水を追加する前は 1 リットル入っており、4 リットル追加して加湿器には 5 リットルの水が入っています。
- 時刻 7 : 水を追加する前は 2 リットル入っており、1 リットル追加して加湿器には 3 リットルの水が入っています。
時刻 7 に水を追加し終えたとき、加湿器に残っている水の量は 3 リットルです。よって答えは 3 です。
入力例 2
3 1 8 10 11 21 5
出力例 2
5
入力例 3
10 2 1 22 10 26 17 29 2 45 20 47 32 72 12 75 1 81 31 97 7
出力例 3
57
Score : 150 points
Problem Statement
There is one humidifier in the AtCoder company office. The current time is 0, and the humidifier has no water inside.
You will add water to this humidifier N times. The i-th addition of water (1 \leq i \leq N) takes place at time T_i, and you add V_i liters of water. It is guaranteed that T_i < T_{i+1} for all 1 \leq i \leq N-1.
However, the humidifier has a leak, and as long as there is water inside, the amount of water decreases by 1 liter per unit time.
Find the amount of water remaining in the humidifier immediately after you finish adding water at time T_N.
Constraints
- 1 \leq N \leq 100
- 1 \leq T_i \leq 100 (1 \leq i \leq N)
- 1 \leq V_i \leq 100 (1 \leq i \leq N)
- T_i < T_{i+1} (1 \leq i \leq N-1)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T_1 V_1 T_2 V_2 \vdots T_N V_N
Output
Print the answer.
Sample Input 1
4 1 3 3 1 4 4 7 1
Sample Output 1
3
At each point in time, water is added as follows:
- Time 1: Before adding, the humidifier has 0 liters. After adding 3 liters, it has 3 liters.
- Time 3: Before adding, it has 1 liter. After adding 1 liter, it has 2 liters total.
- Time 4: Before adding, it has 1 liter. After adding 4 liters, it has 5 liters total.
- Time 7: Before adding, it has 2 liters. After adding 1 liter, it has 3 liters total.
After finishing the addition at time 7, the humidifier contains 3 liters. Thus, the answer is 3.
Sample Input 2
3 1 8 10 11 21 5
Sample Output 2
5
Sample Input 3
10 2 1 22 10 26 17 29 2 45 20 47 32 72 12 75 1 81 31 97 7
Sample Output 3
57
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
N 個の商品があります。高橋君と青木君がどの商品を欲しがっているかを表す長さ N の文字列 T,A が与えられます。T,A の i\ (1\leq i\leq N) 文字目をそれぞれ T_i,A_i とします。
高橋君は T_i が o のとき i 番目の商品を欲しがっており、T_i が x のとき i 番目の商品を欲しがっていません。
同様に、青木君は A_i が o のとき i 番目の商品を欲しがっており、A_i が x のとき i 番目の商品を欲しがっていません。
2 人ともが欲しがっている商品が存在するか判定してください。
制約
- 1\leq N\leq 100
- N は整数
- T,A は
oおよびxからなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N T A
出力
2 人とも欲しがっている商品が存在するならば Yes を、存在しないならば No を出力せよ。
入力例 1
4 oxoo xoox
出力例 1
Yes
3 つ目の商品は 2 人ともが欲しがっているため、Yes を出力します。
入力例 2
5 xxxxx ooooo
出力例 2
No
2 人とも欲しがっている商品は存在しないため、No を出力します。
入力例 3
10 xoooxoxxxo ooxooooxoo
出力例 3
Yes
Score : 100 points
Problem Statement
There are N items. You are given strings T and A of length N that represent which items Takahashi and Aoki want, respectively. Let T_i and A_i be the i-th (1\leq i\leq N) characters of T and A, respectively.
Takahashi wants the i-th item when T_i is o, and does not want the i-th item when T_i is x.
Similarly, Aoki wants the i-th item when A_i is o, and does not want the i-th item when A_i is x.
Determine whether there exists an item that both of them want.
Constraints
- 1\leq N\leq 100
- N is an integer.
- T and A are strings of length N consisting of
oandx.
Input
The input is given from Standard Input in the following format:
N T A
Output
If there exists an item that both of them want, output Yes; otherwise, output No.
Sample Input 1
4 oxoo xoox
Sample Output 1
Yes
The third item is wanted by both of them, so output Yes.
Sample Input 2
5 xxxxx ooooo
Sample Output 2
No
There is no item that both of them want, so output No.
Sample Input 3
10 xoooxoxxxo ooxooooxoo
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
H 行 W 列のブロックからなる長方形状のチョコレートがあります。
Q 個のクエリが与えられるので、順に処理したときの各クエリの答えを求めてください。各クエリは、以下のいずれかの形式です。
-
タイプ 1 : 整数 R が与えられる。下 R 行のチョコレートのブロックの個数を求め、それらを食べる。
-
タイプ 2 : 整数 C が与えられる。右 C 列のチョコレートのブロックの個数を求め、それらを食べる。
なお、クエリを順に処理したとき、各クエリを処理した後もチョコレートは長方形状であり、タイプ 1 のクエリを処理する直前の時点でチョコレートは R + 1 行以上存在し、タイプ 2 のクエリを処理する直前の時点でチョコレートは C + 1 列以上存在します。
制約
- 2 \leq H, W \leq 100
- 1 \leq Q \leq 100
- タイプ 1 のクエリについて、1 \leq R
- クエリを順に処理したとき、タイプ 1 のクエリを処理する直前にチョコレートは R + 1 行以上存在する
- タイプ 2 のクエリについて、1 \leq C
- クエリを順に処理したとき、タイプ 2 のクエリを処理する直前にチョコレートは C + 1 列以上存在する
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
ただし、\text{query}_i は i 番目のクエリであり、以下のいずれかの形式で与えられる。
1 R
2 C
出力
Q 行出力せよ。 i (1 \leq i \leq Q) 行目には i 番目のクエリに対する答えを出力せよ。
入力例 1
7 9 5 2 4 1 3 2 1 2 1 1 3
出力例 1
28 15 4 4 9
はじめ、チョコレートは 7 行 9 列の長方形状です。
1 番目のクエリでは、右 4 列のチョコレートの個数は 28 個であるため 28 を出力します。チョコレートは 7 行 5 列となります。
2 番目のクエリでは、下 3 行のチョコレートの個数は 15 個であるため 15 を出力します。チョコレートは 4 行 5 列となります。
3 番目のクエリでは、右 1 列のチョコレートの個数は 4 個であるため 4 を出力します。チョコレートは 4 行 4 列となります。
4 番目のクエリでは、右 1 列のチョコレートの個数は 4 個であるため 4 を出力します。チョコレートは 4 行 3 列となります。
5 番目のクエリでは、下 3 行のチョコレートの個数は 9 個であるため 9 を出力します。チョコレートは 1 行 3 列となります。
Score : 200 points
Problem Statement
There is a rectangular chocolate consisting of H rows and W columns of blocks.
You are given Q queries; process them in order and find the answer to each query. Each query is in one of the following formats:
-
Type 1: An integer R is given. Find the number of chocolate blocks in the bottom R rows, then eat them.
-
Type 2: An integer C is given. Find the number of chocolate blocks in the rightmost C columns, then eat them.
When the queries are processed in order, the chocolate remains rectangular after each query is processed, and it has at least R + 1 rows immediately before processing a type 1 query and has at least C + 1 columns immediately before processing a type 2 query.
Constraints
- 2 \leq H, W \leq 100
- 1 \leq Q \leq 100
- For type 1 queries, 1 \leq R.
- When the queries are processed in order, the chocolate has at least R + 1 rows immediately before processing a type 1 query.
- For type 2 queries, 1 \leq C.
- When the queries are processed in order, the chocolate has at least C + 1 columns immediately before processing a type 2 query.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Here, \text{query}_i is the i-th query, given in one of the following formats:
1 R
2 C
Output
Output Q lines. The i-th line (1 \leq i \leq Q) should contain the answer to the i-th query.
Sample Input 1
7 9 5 2 4 1 3 2 1 2 1 1 3
Sample Output 1
28 15 4 4 9
Initially, the chocolate is a rectangle with 7 rows and 9 columns.
For the first query, the number of chocolate blocks in the rightmost 4 columns is 28, so output 28. The chocolate becomes 7 rows and 5 columns.
For the second query, the number of chocolate blocks in the bottom 3 rows is 15, so output 15. The chocolate becomes 4 rows and 5 columns.
For the third query, the number of chocolate blocks in the rightmost 1 column is 4, so output 4. The chocolate becomes 4 rows and 4 columns.
For the fourth query, the number of chocolate blocks in the rightmost 1 column is 4, so output 4. The chocolate becomes 4 rows and 3 columns.
For the fifth query, the number of chocolate blocks in the bottom 3 rows is 9, so output 9. The chocolate becomes 1 row and 3 columns.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
空の数列 A があります。クエリが Q 個与えられるので、与えられた順に処理してください。
クエリは次の 2 種類のいずれかです。
1 x: A の末尾に x を追加する。2 k: A の後ろから k 番目の値を求める。このクエリが与えられるとき、A の長さは k 以上であることが保証される。
制約
- 1 \leq Q \leq 100
- 1 種類目のクエリにおいて x は 1 \leq x \leq 10^9 を満たす整数
- 2 種類目のクエリにおいて k はその時点の数列 A の長さ以下の正の整数
入力
入力は以下の形式で標準入力から与えられる。
Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
クエリは以下の 2 つのいずれかの形式である。
1 x
2 k
出力
2 種類目のクエリの個数を q として q 行出力せよ。
i 行目にはそのような i 回目のクエリに対する答えを出力せよ。
入力例 1
5 1 20 1 30 2 1 1 40 2 3
出力例 1
30 20
- 最初 A は空である。
- 1 番目のクエリにより A の末尾に 20 が追加され A=(20) となる。
- 2 番目のクエリにより A の末尾に 30 が追加され A=(20,30) となる。
- 3 番目のクエリの答えは A=(20,30) の後ろから 1 番目の値の 30 である。
- 4 番目のクエリにより A の末尾に 40 が追加され A=(20,30,40) となる。
- 5 番目のクエリの答えは A=(20,30,40) の後ろから 3 番目の値の 20 である。
Score: 200 points
Problem Statement
You have an empty sequence A. There are Q queries given, and you need to process them in the order they are given.
The queries are of the following two types:
1 x: Append x to the end of A.2 k: Find the k-th value from the end of A. It is guaranteed that the length of A is at least k when this query is given.
Constraints
- 1 \leq Q \leq 100
- In the first type of query, x is an integer satisfying 1 \leq x \leq 10^9.
- In the second type of query, k is a positive integer not greater than the current length of sequence A.
Input
The input is given from Standard Input in the following format:
Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
Each query is in one of the following two formats:
1 x
2 k
Output
Print q lines, where q is the number of queries of the second type.
The i-th line should contain the answer to the i-th such query.
Sample Input 1
5 1 20 1 30 2 1 1 40 2 3
Sample Output 1
30 20
- Initially, A is empty.
- The first query appends 20 to the end of A, making A=(20).
- The second query appends 30 to the end of A, making A=(20,30).
- The answer to the third query is 30, which is the 1-st value from the end of A=(20,30).
- The fourth query appends 40 to the end of A, making A=(20,30,40).
- The answer to the fifth query is 20, which is the 3-rd value from the end of A=(20,30,40).
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋くんは、頭パーツを 1 個と体パーツを 1 個組み合わせてロボットを 1 体作ることができます。 ロボットは頭パーツの重さが体パーツの重さより大きいと倒れてしまいます。
現在、高橋くんは頭パーツを N 個と体パーツを M 個持っています。 高橋くんが持っている i 番目 (1\le i\le N) の頭パーツの重さは H _ i グラム、i 番目 (1\le i\le M) の体パーツの重さは B _ i グラムです。
高橋くんは、持っているパーツを適切に組み合わせることで、倒れないロボットを合計 K 体作りたいです。 うまくパーツを組み合わせることで高橋くんが目標を達成することができるか判定してください。
ただし、1 個のパーツを複数のロボットを作るために利用したり、1 体のロボットを作るために頭パーツを 2 個以上(もしくは体パーツを 2 個以上)利用することはできません。
制約
- 1\le N\le2\times10 ^ 5
- 1\le M\le2\times10 ^ 5
- 1\le K\le\min\lbrace N,M\rbrace
- 1\le H _ i\le10 ^ 9\ (1\le i\le N)
- 1\le B _ i\le10 ^ 9\ (1\le i\le M)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M K H _ 1 H _ 2 \ldots H _ N B _ 1 B _ 2 \ldots B _ M
出力
高橋くんがパーツをうまく組み合わせて倒れないロボットを K 体作ることができるなら Yes を、そうでなければ No を出力せよ。
入力例 1
6 6 3 2 7 1 8 2 8 1 8 2 8 4 5
出力例 1
Yes
i 番目の頭パーツと j 番目の体パーツを組み合わせることを (i,j) と書くことにすると、高橋くんは例えば (1,2),(2,4),(3,6) のように組み合わせることで 3 体の倒れないロボットを作ることができます。
よって、Yes を出力してください。
入力例 2
1 1 1 43 1
出力例 2
No
高橋くんが持っている頭パーツが重すぎるため、高橋くんは倒れないロボットを作ることができません。
入力例 3
1 1 1 100 100
出力例 3
Yes
頭の重さと体の重さが等しい場合、ロボットは倒れないことに注意してください。
入力例 4
12 15 12 748 169 586 329 972 529 432 519 408 587 138 249 656 114 632 299 984 755 404 772 155 506 832 854 353 465 387
出力例 4
Yes
Score : 300 points
Problem Statement
Takahashi can combine a head part and a body part to create a robot. A robot falls over if the weight of the head part is greater than the weight of the body part.
Currently, he has N head parts and M body parts. The weight of the i-th (1\le i\le N) head part is H _ i grams, and the weight of the i-th (1\le i\le M) body part is B _ i grams.
He wants to create a total of K robots that do not fall over by appropriately combining the parts he has. Determine whether he can achieve his goal by combining the parts well.
Here, a part cannot be used to create multiple robots, and two or more head parts (or two or more body parts) cannot be used to create one robot.
Constraints
- 1\le N\le2\times10 ^ 5
- 1\le M\le2\times10 ^ 5
- 1\le K\le\min\lbrace N,M\rbrace
- 1\le H _ i\le10 ^ 9\ (1\le i\le N)
- 1\le B _ i\le10 ^ 9\ (1\le i\le M)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M K H _ 1 H _ 2 \ldots H _ N B _ 1 B _ 2 \ldots B _ M
Output
Print Yes if Takahashi can combine the parts well to create K robots that do not fall over; otherwise, print No.
Sample Input 1
6 6 3 2 7 1 8 2 8 1 8 2 8 4 5
Sample Output 1
Yes
If we denote combining the i-th head part and the j-th body part as (i,j), then Takahashi can create three robots that do not fall over by combining them as (1,2),(2,4),(3,6), for example.
Thus, print Yes.
Sample Input 2
1 1 1 43 1
Sample Output 2
No
His head part is too heavy, so he cannot create any robot that does not fall over.
Sample Input 3
1 1 1 100 100
Sample Output 3
Yes
Note that a robot does not fall over if the head and body have equal weights.
Sample Input 4
12 15 12 748 169 586 329 972 529 432 519 408 587 138 249 656 114 632 299 984 755 404 772 155 506 832 854 353 465 387
Sample Output 4
Yes