Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は図書館で働いています。図書館の本棚には N 冊の本が一列に並んでおり、それぞれの本には管理番号が付けられています。左から i 番目(1 \leq i \leq N)の本の管理番号は A_i です。なお、異なる本が同じ管理番号を持つこともあります。
青木君が「管理番号が K の本を探しているのですが、どこにありますか?」と尋ねました。
本棚に並んでいる N 冊の本の中から、管理番号がちょうど K である本を見つけてください。管理番号が K の本が存在する場合は、その本の位置(左から数えて何番目か、1 始まり)のうち最も小さいものを出力してください。存在しない場合は -1 を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^9
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数
入力
N K A_1 A_2 \ldots A_N
- 1 行目には、本の冊数を表す整数 N と、探している管理番号を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各本の管理番号を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
管理番号がちょうど K である本が存在する場合は、その本の位置(左から数えて何番目か、1 始まり)のうち最も小さいものを 1 行で出力せよ。存在しない場合は -1 を出力せよ。
入力例 1
5 3 1 4 3 2 3
出力例 1
3
入力例 2
7 100 50 200 100 100 300 100 400
出力例 2
3
入力例 3
10 999999999 1 1000000000 500000000 123456789 999999999 999999999 777777777 888888888 999999999 1
出力例 3
5
Score : 200 pts
Problem Statement
Takahashi works at a library. On a bookshelf in the library, N books are lined up in a row, and each book has a catalog number assigned to it. The catalog number of the i-th book from the left (1 \leq i \leq N) is A_i. Note that different books may have the same catalog number.
Aoki asks, "I'm looking for the book with catalog number K. Where is it?"
Among the N books on the bookshelf, find the book whose catalog number is exactly K. If a book with catalog number K exists, output the smallest position of such a book (counted from the left, 1-indexed). If no such book exists, output -1.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^9
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- All inputs are integers
Input
N K A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of books and an integer K representing the catalog number being searched for, separated by a space.
- The second line contains integers A_1, A_2, \ldots, A_N representing the catalog numbers of the books, separated by spaces.
Output
If a book with catalog number exactly K exists, output on a single line the smallest position of such a book (counted from the left, 1-indexed). If no such book exists, output -1.
Sample Input 1
5 3 1 4 3 2 3
Sample Output 1
3
Sample Input 2
7 100 50 200 100 100 300 100 400
Sample Output 2
3
Sample Input 3
10 999999999 1 1000000000 500000000 123456789 999999999 999999999 777777777 888888888 999999999 1
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君は農園で収穫された果物の出荷作業を担当しています。
農園では N 個の果物が収穫され、それぞれ 1 から N までの番号が付けられています。各果物 i (1 \leq i \leq N) には糖度 A_i が測定されており、この値が大きいほど甘くて美味しい果物です。
今回、傷がついてしまった果物が M 個見つかりました。傷のある果物の番号は B_1, B_2, \ldots, B_M として与えられます(順序に特別な意味はありません)。
通常、傷のある果物は規格外品として通常とは別のルートで出荷されます。しかし、糖度が K 以上(すなわち A_i \geq K)の果物は特別に高級品として扱われるため、傷があっても規格外品とはせず、通常の出荷ルートに含めることになりました。
まとめると、傷があり、かつ糖度が K 未満の果物が規格外品として出荷されます。
高橋君が最終的に規格外品として出荷すべき果物の個数と、それらの果物の糖度の合計を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq N
- 1 \leq K \leq 10^9
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq B_j \leq N (1 \leq j \leq M)
- B_1, B_2, \ldots, B_M はすべて異なる
- 入力はすべて整数
入力
N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
- 1 行目には、果物の総数を表す N 、傷のある果物の個数を表す M 、高級品として扱う基準となる糖度を表す K が、スペース区切りで与えられる。
- 2 行目には、各果物の糖度を表す A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
- A_i は果物 i の糖度を表す。
- 3 行目には、傷のある果物の番号を表す B_1, B_2, \ldots, B_M が、スペース区切りで与えられる。
- B_j は傷のある果物の番号を表す。
出力
規格外品として出荷すべき果物の個数と、それらの果物の糖度の合計を、スペース区切りで 1 行に出力せよ。
入力例 1
5 3 10 8 12 5 15 7 1 3 4
出力例 1
2 13
入力例 2
8 5 20 25 18 30 12 8 22 15 19 2 4 5 6 8
出力例 2
4 57
入力例 3
15 7 100 150 80 95 200 45 120 75 180 90 60 110 55 130 85 70 3 5 7 9 10 12 14
出力例 3
7 505
Score : 266 pts
Problem Statement
Takahashi is in charge of shipping fruits harvested at a farm.
N fruits have been harvested at the farm, each numbered from 1 to N. For each fruit i (1 \leq i \leq N), a sweetness level A_i has been measured; the higher this value, the sweeter and more delicious the fruit.
It was discovered that M fruits have bruises. The numbers of the bruised fruits are given as B_1, B_2, \ldots, B_M (the order has no special meaning).
Normally, bruised fruits are shipped as substandard products through a separate route from the regular one. However, fruits with a sweetness level of K or higher (i.e., A_i \geq K) are treated specially as premium products, so even if they have bruises, they are not classified as substandard and are included in the regular shipping route.
In summary, fruits that have bruises and have a sweetness level less than K are shipped as substandard products.
Find the number of fruits that Takahashi should ultimately ship as substandard products, and the total sweetness level of those fruits.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq N
- 1 \leq K \leq 10^9
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq B_j \leq N (1 \leq j \leq M)
- B_1, B_2, \ldots, B_M are all distinct
- All inputs are integers
Input
N M K A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
- The first line contains N representing the total number of fruits, M representing the number of bruised fruits, and K representing the sweetness threshold for premium classification, separated by spaces.
- The second line contains the sweetness levels of each fruit A_1, A_2, \ldots, A_N, separated by spaces.
- A_i represents the sweetness level of fruit i.
- The third line contains the numbers of the bruised fruits B_1, B_2, \ldots, B_M, separated by spaces.
- B_j represents the number of a bruised fruit.
Output
Print the number of fruits to be shipped as substandard products and the total sweetness level of those fruits, separated by a space, on a single line.
Sample Input 1
5 3 10 8 12 5 15 7 1 3 4
Sample Output 1
2 13
Sample Input 2
8 5 20 25 18 30 12 8 22 15 19 2 4 5 6 8
Sample Output 2
4 57
Sample Input 3
15 7 100 150 80 95 200 45 120 75 180 90 60 110 55 130 85 70 3 5 7 9 10 12 14
Sample Output 3
7 505
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は学校の理科の授業で、 N 種類の植物を育てる実験を行っています。
それぞれの植物は、実験開始時の高さと、1日あたりの成長量が異なります。具体的には、 i 番目の植物( 1 \leq i \leq N )は、実験開始時( 0 日目)の高さが A_i cm であり、1日あたり B_i cm ずつ成長します。すなわち、 d 日目( d = 0, 1, 2, \ldots )における i 番目の植物の高さは A_i + B_i \times d cm です。
高橋君は 0 日目, 1 日目, 2 日目, \ldots と毎日植物の高さを確認し、すべての植物の高さが M cm 以上になった最初の日に観察を終了する計画です。
観察が終了する日、すなわち、すべての i ( 1 \leq i \leq N )について A_i + B_i \times d \geq M が成り立つような最小の非負整数 d を求めてください。
なお、制約の条件のもとで、答えは必ず有限の値として存在します。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 10^9
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- 入力はすべて整数である
入力
N M A_1 B_1 A_2 B_2 \vdots A_N B_N
- 1 行目には、植物の種類数を表す整数 N と、目標の高さを表す整数 M が、スペース区切りで与えられる。
- 続く N 行のうち i 行目( 1 \leq i \leq N )には、 i 番目の植物の実験開始時の高さ A_i と、1日あたりの成長量 B_i が、スペース区切りで与えられる。
出力
すべての植物の高さが M cm 以上となる最小の非負整数 d を 1 行で出力せよ。
入力例 1
3 10 2 3 5 2 8 1
出力例 1
3
入力例 2
4 100 100 5 90 10 95 3 80 4
出力例 2
5
入力例 3
5 1000000000 1 1 500000000 100000000 999999999 1 100000000 300000000 250000000 250000000
出力例 3
999999999
Score : 300 pts
Problem Statement
Takahashi is conducting an experiment growing N types of plants in his school science class.
Each plant has a different initial height and daily growth rate. Specifically, the i-th plant (1 \leq i \leq N) has a height of A_i cm at the start of the experiment (day 0) and grows by B_i cm per day. That is, the height of the i-th plant on day d (d = 0, 1, 2, \ldots) is A_i + B_i \times d cm.
Takahashi plans to check the heights of the plants every day on day 0, day 1, day 2, \ldots, and end the observation on the first day when all plants have a height of at least M cm.
Find the day when the observation ends, that is, the smallest non-negative integer d such that A_i + B_i \times d \geq M holds for all i (1 \leq i \leq N).
Note that under the given constraints, the answer is guaranteed to exist as a finite value.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 10^9
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- All input values are integers
Input
N M A_1 B_1 A_2 B_2 \vdots A_N B_N
- The first line contains an integer N representing the number of plant types and an integer M representing the target height, separated by a space.
- The following N lines each contain, for the i-th line (1 \leq i \leq N), the initial height A_i and the daily growth rate B_i of the i-th plant, separated by a space.
Output
Print on a single line the smallest non-negative integer d such that all plants have a height of at least M cm.
Sample Input 1
3 10 2 3 5 2 8 1
Sample Output 1
3
Sample Input 2
4 100 100 5 90 10 95 3 80 4
Sample Output 2
5
Sample Input 3
5 1000000000 1 1 500000000 100000000 999999999 1 100000000 300000000 250000000 250000000
Sample Output 3
999999999
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は冒険の末、N 個の宝箱が眠る遺跡にたどり着きました。
各宝箱 i(1 \leq i \leq N)には錠前がかかっており、その強度は C_i です。強度の値が大きいほど頑丈な錠前であることを意味します。なお、すべての宝箱の錠前の強度は互いに異なります。
高橋君は M 本の鍵を持っています。各鍵 j(1 \leq j \leq M)には開錠能力 R_j が備わっています。鍵 j で宝箱 i を開けることができるのは、鍵の開錠能力が錠前の強度以上である場合、すなわち C_i \leq R_j のときに限ります。なお、異なる鍵が同じ開錠能力を持つこともあります。
高橋君は、開けたい宝箱をいくつか(0 個でもよい)選び、選んだ宝箱それぞれに鍵を 1 本ずつ割り当てて開けます。ただし、同じ鍵を 2 つ以上の宝箱に割り当てることはできません。また、各宝箱に割り当てた鍵はその宝箱を開けられるもの(C_i \leq R_j)でなければなりません。使わない鍵や開けない宝箱があっても構いません。
高橋君が開けることのできる宝箱の個数の最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq C_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq R_j \leq 10^9 (1 \leq j \leq M)
- C_i \neq C_k (i \neq k)(すべての錠前の強度は互いに異なる)
- 入力はすべて整数
入力
N M C_1 C_2 \ldots C_N R_1 R_2 \ldots R_M
- 1 行目には、宝箱の個数を表す整数 N と、鍵の本数を表す整数 M が空白区切りで与えられる。
- 2 行目には、各宝箱の錠前の強度を表す整数 C_1, C_2, \ldots, C_N が空白区切りで与えられる。
- 3 行目には、各鍵の開錠能力を表す整数 R_1, R_2, \ldots, R_M が空白区切りで与えられる。
出力
高橋君が開けることのできる宝箱の個数の最大値を 1 行で出力せよ。
入力例 1
3 3 10 20 30 15 25 35
出力例 1
3
入力例 2
5 3 100 200 300 400 500 150 250 450
出力例 2
3
入力例 3
7 10 50 120 80 200 350 500 1000 40 60 100 100 150 200 300 400 600 1500
出力例 3
7
Score : 366 pts
Problem Statement
After a long adventure, Takahashi has reached ruins containing N treasure chests.
Each treasure chest i (1 \leq i \leq N) is secured with a lock of strength C_i. A larger strength value means a sturdier lock. All treasure chests have mutually distinct lock strengths.
Takahashi has M keys. Each key j (1 \leq j \leq M) has an unlocking power R_j. Key j can open treasure chest i only if the key's unlocking power is at least as large as the lock's strength, that is, when C_i \leq R_j. Note that different keys may have the same unlocking power.
Takahashi selects some treasure chests he wants to open (possibly 0), and assigns exactly one key to each selected treasure chest to open it. However, the same key cannot be assigned to two or more treasure chests. Additionally, the key assigned to each treasure chest must be able to open it (C_i \leq R_j). It is fine to leave some keys unused or some treasure chests unopened.
Find the maximum number of treasure chests Takahashi can open.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq C_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq R_j \leq 10^9 (1 \leq j \leq M)
- C_i \neq C_k (i \neq k) (all lock strengths are mutually distinct)
- All input values are integers
Input
N M C_1 C_2 \ldots C_N R_1 R_2 \ldots R_M
- The first line contains an integer N representing the number of treasure chests and an integer M representing the number of keys, separated by a space.
- The second line contains integers C_1, C_2, \ldots, C_N representing the lock strengths of the treasure chests, separated by spaces.
- The third line contains integers R_1, R_2, \ldots, R_M representing the unlocking powers of the keys, separated by spaces.
Output
Print the maximum number of treasure chests Takahashi can open, on a single line.
Sample Input 1
3 3 10 20 30 15 25 35
Sample Output 1
3
Sample Input 2
5 3 100 200 300 400 500 150 250 450
Sample Output 2
3
Sample Input 3
7 10 50 120 80 200 350 500 1000 40 60 100 100 150 200 300 400 600 1500
Sample Output 3
7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 433 点
問題文
高橋君は駄菓子屋で N 種類のお菓子を見つけました。i 番目 (1 \leq i \leq N) のお菓子の値段は A_i 円です。各お菓子は 1 つずつしか在庫がないため、それぞれのお菓子について「買う」か「買わない」かのどちらかを選びます。なお、異なる種類のお菓子であっても値段が同じことがありますが、それらは異なるお菓子として区別します。
高橋君はちょうど S 円を持っています。せっかくなので、手持ちのお金を余らせず、ぴったり S 円分のお菓子を買いたいと考えています。
N 種類のお菓子から 0 個以上を選ぶ方法のうち、選んだお菓子の値段の合計がちょうど S 円になるような選び方は何通りあるか求めてください。ただし、1 つもお菓子を選ばない場合、値段の合計は 0 円とみなします。
制約
- 1 \leq N \leq 40
- 0 \leq S \leq 10^{12}
- 1 \leq A_i \leq 10^{12}
- 入力はすべて整数
入力
N S A_1 A_2 \ldots A_N
- 1 行目には、お菓子の種類数を表す整数 N と、高橋君の所持金を表す整数 S が、スペース区切りで与えられる。
- 2 行目には、各お菓子の値段を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
選んだお菓子の値段の合計がちょうど S 円になるような選び方の個数を 1 行で出力してください。
入力例 1
4 10 2 3 5 7
出力例 1
2
入力例 2
6 15 1 2 4 5 8 10
出力例 2
4
入力例 3
10 1000000000000 100000000000 200000000000 300000000000 400000000000 500000000000 600000000000 700000000000 800000000000 900000000000 1000000000000
出力例 3
10
Score : 433 pts
Problem Statement
Takahashi found N kinds of sweets at a candy shop. The price of the i-th (1 \leq i \leq N) sweet is A_i yen. Since there is only one of each sweet in stock, for each sweet he must choose either "buy" or "don't buy." Note that different kinds of sweets may have the same price, but they are still distinguished as different sweets.
Takahashi has exactly S yen. Since he wants to make the most of it, he would like to buy sweets that cost exactly S yen in total, without leaving any money.
Among all ways to select 0 or more sweets from the N kinds, find the number of ways such that the total price of the selected sweets is exactly S yen. Note that if no sweets are selected, the total price is considered to be 0 yen.
Constraints
- 1 \leq N \leq 40
- 0 \leq S \leq 10^{12}
- 1 \leq A_i \leq 10^{12}
- All inputs are integers
Input
N S A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of kinds of sweets and an integer S representing the amount of money Takahashi has, separated by a space.
- The second line contains integers A_1, A_2, \ldots, A_N representing the price of each sweet, separated by spaces.
Output
Print in one line the number of ways to select sweets such that the total price of the selected sweets is exactly S yen.
Sample Input 1
4 10 2 3 5 7
Sample Output 1
2
Sample Input 2
6 15 1 2 4 5 8 10
Sample Output 2
4
Sample Input 3
10 1000000000000 100000000000 200000000000 300000000000 400000000000 500000000000 600000000000 700000000000 800000000000 900000000000 1000000000000
Sample Output 3
10