実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 233 点
問題文
高橋君は、ハイキングコースの入口に立っています。目の前には、手前から奥に向かって一列に並んだ N 個の山が見えます。手前から i 番目(1 \leq i \leq N)の山の標高は H_i メートルです。
この問題では、山の見え方を次のような簡単なモデルで考えます。山が見えるかどうかは、その山とそれより手前にある山々の標高の大小関係のみで決まります。山どうしの距離は考慮しません。
具体的には、手前から i 番目の山が見えるとは、次の条件を満たすことを意味します。
- 1 \leq j < i を満たすすべての整数 j について H_j < H_i が成り立つ。
言い換えると、手前にある山(1 番目から i-1 番目まで)の中に標高が H_i 以上のものが 1 つでも存在すれば、i 番目の山は手前の山に隠れて見えません。手前に標高がちょうど同じ山がある場合も見えないことに注意してください。
最も手前にある山(1 番目の山)は、それより手前に山が存在しないため、必ず見えます。
高橋君から見える山の番号(1 から N までの整数)をすべて求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq H_i \leq 10^9
- 入力はすべて整数
入力
N H_1 H_2 \ldots H_N
- 1 行目には、山の数を表す整数 N が与えられる。
- 2 行目には、手前から i 番目(i = 1, 2, \ldots, N)の山の標高(メートル)を表す整数 H_i が、スペース区切りで N 個与えられる。
出力
見える山の番号を小さい順に、スペース区切りで 1 行に出力せよ。末尾に余分なスペースがあっても構わない。
入力例 1
5 3 1 4 1 5
出力例 1
1 3 5
入力例 2
8 10 20 15 25 5 30 28 35
出力例 2
1 2 4 6 8
入力例 3
15 100 50 80 120 110 130 125 140 200 150 180 250 240 300 299
出力例 3
1 4 6 8 9 12 14
Score : 233 pts
Problem Statement
Takahashi is standing at the entrance of a hiking course. In front of him, he can see N mountains lined up in a row from front to back. The elevation of the i-th mountain from the front (1 \leq i \leq N) is H_i meters.
In this problem, we consider the visibility of mountains using the following simple model. Whether a mountain is visible or not is determined solely by the relative heights of that mountain and the mountains in front of it. The distances between mountains are not considered.
Specifically, the i-th mountain from the front is visible if and only if the following condition is satisfied:
- For every integer j satisfying 1 \leq j < i, H_j < H_i holds.
In other words, if there exists even one mountain among the mountains in front (from the 1-st to the (i-1)-th) whose elevation is H_i or greater, then the i-th mountain is hidden behind a mountain in front and is not visible. Note that a mountain is also not visible if there is a mountain in front with exactly the same elevation.
The frontmost mountain (the 1-st mountain) is always visible since there are no mountains in front of it.
Find all the numbers (integers from 1 to N) of the mountains visible to Takahashi.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq H_i \leq 10^9
- All input values are integers.
Input
N H_1 H_2 \ldots H_N
- The first line contains an integer N representing the number of mountains.
- The second line contains N integers H_i separated by spaces, where H_i represents the elevation (in meters) of the i-th mountain from the front (i = 1, 2, \ldots, N).
Output
Print the numbers of the visible mountains in ascending order on a single line, separated by spaces. Trailing spaces are acceptable.
Sample Input 1
5 3 1 4 1 5
Sample Output 1
1 3 5
Sample Input 2
8 10 20 15 25 5 30 28 35
Sample Output 2
1 2 4 6 8
Sample Input 3
15 100 50 80 120 110 130 125 140 200 150 180 250 240 300 299
Sample Output 3
1 4 6 8 9 12 14
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君は旅行から帰ってきました。旅行先で N 個のお土産を購入しましたが、スーツケースには最大 N - K 個しか入らないため、K 個のお土産を諦めなければなりません。
N 個のお土産にはそれぞれ 1 から N までの番号が付いており、お土産 i(1 \leq i \leq N)には満足度 D_i が設定されています。満足度は、そのお土産を持ち帰ったときに得られる嬉しさを表します。
高橋君は、N 個のお土産の中から異なる K 個を選んで諦め、残りの N - K 個をすべて持ち帰ります。持ち帰ったお土産の満足度の合計値を最大化するように、諦めるお土産を最適に選びたいです。
持ち帰るお土産の満足度の合計値の最大値を求めてください。
制約
- 1 \leq K < N \leq 2 \times 10^5
- 1 \leq D_i \leq 10^9
- 入力はすべて整数
入力
N K D_1 D_2 \ldots D_N
- 1 行目には、お土産の総数を表す整数 N と、諦めるお土産の個数を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、お土産 i の満足度を表す整数 D_i(1 \leq i \leq N)が、D_1, D_2, \ldots, D_N の順にスペース区切りで与えられる。
出力
持ち帰るお土産の満足度の合計値の最大値を 1 行で出力してください。
入力例 1
5 2 3 1 4 1 5
出力例 1
12
入力例 2
8 3 10 20 30 40 50 60 70 80
出力例 2
300
入力例 3
15 6 1000000000 1 999999999 2 888888888 3 777777777 4 666666666 5 555555555 6 444444444 7 333333333
出力例 3
5666666669
Score : 300 pts
Problem Statement
Takahashi has returned from a trip. He purchased N souvenirs at his destination, but since his suitcase can hold at most N - K items, he must give up K souvenirs.
Each of the N souvenirs is numbered from 1 to N, and souvenir i (1 \leq i \leq N) has a satisfaction value D_i. The satisfaction value represents the happiness gained from bringing that souvenir home.
Takahashi will choose K distinct souvenirs from the N souvenirs to give up, and bring home all of the remaining N - K souvenirs. He wants to optimally choose which souvenirs to give up so as to maximize the total satisfaction value of the souvenirs he brings home.
Find the maximum possible total satisfaction value of the souvenirs he brings home.
Constraints
- 1 \leq K < N \leq 2 \times 10^5
- 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 two integers separated by a space: N, the total number of souvenirs, and K, the number of souvenirs to give up.
- The second line contains the integers D_i (1 \leq i \leq N), representing the satisfaction value of souvenir i, given in the order D_1, D_2, \ldots, D_N, separated by spaces.
Output
Print the maximum possible total satisfaction value of the souvenirs he brings home, on a single line.
Sample Input 1
5 2 3 1 4 1 5
Sample Output 1
12
Sample Input 2
8 3 10 20 30 40 50 60 70 80
Sample Output 2
300
Sample Input 3
15 6 1000000000 1 999999999 2 888888888 3 777777777 4 666666666 5 555555555 6 444444444 7 333333333
Sample Output 3
5666666669
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 366 点
問題文
高橋君は工作教室の先生をしています。今日の授業では、生徒たちにロープを使った工作を教える予定です。
教室には N 人の生徒がおり、高橋君は長さ L のロープを1本持っています。高橋君はこのロープを切り分けて生徒たちに配ることで、できるだけ多くの生徒に工作に参加してもらいたいと考えています。
ロープの切り分けと配布には以下のルールがあります。
- ロープを切る回数は 0 回以上 K 回以下である。1本のロープ上の好きな位置を選んで k 回 (0 \leq k \leq K) 切ると、ちょうど k + 1 本のピースに分かれる。各ピースの長さは任意の正の実数(すなわち 0 より大きい任意の実数)でよい。
- 切り分けた各ピースは、高々1人の生徒に配ることができる。どの生徒にも配らないピースがあってもよい。
- 各生徒が受け取れるピースは高々1本である。ピースを受け取らない生徒がいてもよい。
- i 番目の生徒 (1 \leq i \leq N) は、長さが A_i 以上のピースを1本受け取ったとき、またそのときに限り、工作に参加できる。
高橋君がロープの切り方および生徒への配り方を最適に選ぶとき、工作に参加できる生徒の最大人数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq L \leq 10^9
- 0 \leq K \leq N
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数である
入力
N L K A_1 A_2 \ldots A_N
- 1 行目には、生徒の人数を表す N 、ロープの長さを表す L 、最大カット回数を表す K が、スペース区切りで与えられる。
- 2 行目には、各生徒が工作に参加するために必要なロープの最小の長さ A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
最適にロープを切り分けて配るとき、工作に参加できる生徒の最大人数を 1 行で出力せよ。
入力例 1
4 10 2 3 2 4 5
出力例 1
3
入力例 2
5 15 3 5 3 4 6 2
出力例 2
4
入力例 3
8 1000000000 5 100000000 200000000 150000000 300000000 50000000 250000000 400000000 100000000
出力例 3
6
Score : 366 pts
Problem Statement
Takahashi is a teacher at a crafting class. In today's lesson, he plans to teach the students a craft using rope.
There are N students in the classroom, and Takahashi has one rope of length L. He wants to cut this rope into pieces and distribute them to the students so that as many students as possible can participate in the craft.
The following rules apply to cutting and distributing the rope:
- The number of cuts made to the rope is between 0 and K, inclusive. By choosing k (0 \leq k \leq K) positions on a single rope and cutting it, the rope is divided into exactly k + 1 pieces. The length of each piece may be any positive real number (that is, any real number greater than 0).
- Each piece can be given to at most one student. It is allowed for some pieces not to be given to any student.
- Each student can receive at most one piece. It is allowed for some students not to receive any piece.
- The i-th student (1 \leq i \leq N) can participate in the craft if and only if they receive a piece of length at least A_i.
When Takahashi optimally chooses how to cut the rope and how to distribute the pieces to the students, find the maximum number of students who can participate in the craft.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq L \leq 10^9
- 0 \leq K \leq N
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers.
Input
N L K A_1 A_2 \ldots A_N
- The first line contains N representing the number of students, L representing the length of the rope, and K representing the maximum number of cuts, separated by spaces.
- The second line contains A_1, A_2, \ldots, A_N, the minimum rope lengths required for each student to participate in the craft, separated by spaces.
Output
Print in one line the maximum number of students who can participate in the craft when the rope is cut and distributed optimally.
Sample Input 1
4 10 2 3 2 4 5
Sample Output 1
3
Sample Input 2
5 15 3 5 3 4 6 2
Sample Output 2
4
Sample Input 3
8 1000000000 5 100000000 200000000 150000000 300000000 50000000 250000000 400000000 100000000
Sample Output 3
6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は N 人の選手が所属するスポーツクラブの監督です。選手には 1 から N までの番号が付けられており、番号が異なれば別の選手として区別します。選手 i(1 \leq i \leq N)の実力値は整数 W_i です。
高橋君はこれから、N 人の選手の中からチームを編成しようとしています。各選手について「選ぶ」か「選ばない」かをちょうど一度ずつ決めます(同じ選手を複数回選ぶことはできません)。このようなチームの選び方は、誰も選ばない場合も含めて 2^N 通り考えられます。
\lfloor x \rfloor で x 以下の最大の整数を表すことにします。2^N 通りの選び方のうち、選ばれた選手の人数が \lfloor N/2 \rfloor + 1 人以上であるものを有効な選び方と呼びます。例えば、N = 5 のときは 3 人以上、N = 6 のときは 4 人以上選ぶ必要があります。
有効な選び方のそれぞれに対して、選ばれた選手の実力値の合計をスコアと定義します。全ての有効な選び方について、それぞれのスコアを求め、それらを全て足し合わせた値を求めてください。異なる選び方が同じスコアを持つ場合も、それぞれ別々に加算します。
答えは非常に大きくなる可能性があるので、998244353 で割った余りを出力してください。
制約
- 1 \leq N \leq 5 \times 10^5
- 1 \leq W_i \leq 10^9
- 入力はすべて整数である。
入力
N W_1 W_2 \ldots W_N
- 1 行目には、選手の人数を表す整数 N が与えられる。
- 2 行目には、各選手の実力値を表す N 個の整数 W_1, W_2, \ldots, W_N がスペース区切りで与えられる。
出力
全ての有効な選び方のスコアを足し合わせた値を 998244353 で割った余りを 1 行で出力せよ。
入力例 1
3 1 2 3
出力例 1
18
入力例 2
4 1 2 3 4
出力例 2
40
入力例 3
10 1 2 3 4 5 6 7 8 9 10
出力例 3
14080
入力例 4
20 15 92 65 35 89 79 32 38 46 26 43 38 32 79 50 28 84 19 71 69
出力例 4
270008320
入力例 5
1 1000000000
出力例 5
1755647
Score : 400 pts
Problem Statement
Takahashi is the coach of a sports club with N players. The players are numbered from 1 to N, and players with different numbers are considered distinct. The skill value of player i (1 \leq i \leq N) is an integer W_i.
Takahashi is going to form a team from the N players. For each player, he decides exactly once whether to "select" or "not select" them (the same player cannot be selected multiple times). Including the case where no one is selected, there are 2^N possible ways to form a team.
Let \lfloor x \rfloor denote the largest integer not exceeding x. Among the 2^N possible selections, those where the number of selected players is at least \lfloor N/2 \rfloor + 1 are called valid selections. For example, when N = 5, at least 3 players must be selected, and when N = 6, at least 4 players must be selected.
For each valid selection, the score is defined as the sum of the skill values of the selected players. For all valid selections, compute each score and find the total sum of all these scores. If different selections have the same score, each is counted separately in the sum.
Since the answer can be very large, output the remainder when divided by 998244353.
Constraints
- 1 \leq N \leq 5 \times 10^5
- 1 \leq W_i \leq 10^9
- All inputs are integers.
Input
N W_1 W_2 \ldots W_N
- The first line contains an integer N, representing the number of players.
- The second line contains N integers W_1, W_2, \ldots, W_N separated by spaces, representing the skill values of each player.
Output
Output in one line the remainder when the total sum of scores over all valid selections is divided by 998244353.
Sample Input 1
3 1 2 3
Sample Output 1
18
Sample Input 2
4 1 2 3 4
Sample Output 2
40
Sample Input 3
10 1 2 3 4 5 6 7 8 9 10
Sample Output 3
14080
Sample Input 4
20 15 92 65 35 89 79 32 38 46 26 43 38 32 79 50 28 84 19 71 69
Sample Output 4
270008320
Sample Input 5
1 1000000000
Sample Output 5
1755647
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 433 点
問題文
高橋君は N 個の区画からなる工業団地の管理者です。各区画には 1 から N までの番号が付けられており、区画 i には最大 P_i トンの荷物を保管できる倉庫を建設できます。
ある日、工業団地に合計 M トン分の荷物の保管依頼がありました。高橋君は、後述する条件を満たしながら、できるだけ多くの荷物を保管したいと考えています。
工業団地には K 本の通路があり、i 本目の通路は区画 U_i と区画 V_i を直接つないでいます。通路で直接つながっている 2 つの区画に同時に倉庫を建設すると、搬入トラックの動線が干渉するため、そのような配置は 禁止 されています。通路で直接つながっていない 2 つの区画であれば、同時に倉庫を建設しても問題ありません。
具体的には、高橋君は以下の手順で荷物を保管します。
- 倉庫を建設する区画の集合 S を選ぶ(S は空集合でもよい)。ただし、S に含まれるどの 2 つの区画も通路で直接つながっていてはならない。
- S に含まれる各区画 i に対して、0 以上 P_i 以下の整数値の荷物量を割り当てる。S に含まれない区画には倉庫がないため、荷物量は 0 とする。
- すべての区画の荷物量の合計は M 以下でなければならない。
このとき、すべての区画の荷物量の合計としてあり得る最大値を求めてください。
制約
- 1 \leq N \leq 40
- 1 \leq M \leq 10^{15}
- 0 \leq K \leq \frac{N(N-1)}{2}
- 1 \leq P_i \leq 10^{12} (1 \leq i \leq N)
- 1 \leq U_i < V_i \leq N (1 \leq i \leq K)
- (U_i, V_i) \neq (U_j, V_j) (i \neq j)
- 入力はすべて整数
入力
N M K P_1 P_2 \ldots P_N U_1 V_1 U_2 V_2 \vdots U_K V_K
- 1 行目には、区画の数を表す整数 N、保管量の上限を表す整数 M、通路の本数を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各区画の最大保管量を表す整数 P_1, P_2, \ldots, P_N が、スペース区切りで与えられる。
- 3 行目から K + 2 行目には、通路の情報が与えられる。
- 2 + i 行目では、i 本目の通路が区画 U_i と区画 V_i を直接つないでいることを表す。
出力
高橋君が保管できる荷物量の合計の最大値を整数で 1 行に出力してください。
入力例 1
4 10 2 3 5 4 6 1 2 3 4
出力例 1
10
入力例 2
6 100 5 10 20 30 15 25 5 1 2 2 3 3 4 4 5 5 6
出力例 2
65
入力例 3
10 1500000000000 8 100000000000 200000000000 150000000000 300000000000 250000000000 50000000000 400000000000 180000000000 350000000000 120000000000 1 2 2 3 1 5 4 7 4 9 5 6 7 9 8 9
出力例 3
1150000000000
Score : 433 pts
Problem Statement
Takahashi is the manager of an industrial park consisting of N lots. Each lot is numbered from 1 to N, and a warehouse capable of storing up to P_i tons of goods can be built on lot i.
One day, a request was made to store a total of M tons of goods in the industrial park. Takahashi wants to store as many goods as possible while satisfying the conditions described below.
The industrial park has K corridors, where the i-th corridor directly connects lot U_i and lot V_i. Building warehouses simultaneously on two lots that are directly connected by a corridor is prohibited, as the routes of delivery trucks would interfere with each other. If two lots are not directly connected by a corridor, warehouses may be built on both of them simultaneously without any issues.
Specifically, Takahashi stores goods according to the following procedure:
- Choose a set S of lots on which to build warehouses (S may be empty). No two lots in S may be directly connected by a corridor.
- For each lot i in S, assign an integer amount of goods between 0 and P_i inclusive. Lots not in S have no warehouse, so their goods amount is 0.
- The total amount of goods across all lots must be at most M.
Find the maximum possible value of the total amount of goods across all lots.
Constraints
- 1 \leq N \leq 40
- 1 \leq M \leq 10^{15}
- 0 \leq K \leq \frac{N(N-1)}{2}
- 1 \leq P_i \leq 10^{12} (1 \leq i \leq N)
- 1 \leq U_i < V_i \leq N (1 \leq i \leq K)
- (U_i, V_i) \neq (U_j, V_j) (i \neq j)
- All input values are integers
Input
N M K P_1 P_2 \ldots P_N U_1 V_1 U_2 V_2 \vdots U_K V_K
- The first line contains the integer N representing the number of lots, the integer M representing the upper limit on storage, and the integer K representing the number of corridors, separated by spaces.
- The second line contains the integers P_1, P_2, \ldots, P_N representing the maximum storage capacity of each lot, separated by spaces.
- From the 3rd line to the (K + 2)-th line, corridor information is given.
- The (2 + i)-th line indicates that the i-th corridor directly connects lot U_i and lot V_i.
Output
Output the maximum total amount of goods that Takahashi can store, as a single integer on one line.
Sample Input 1
4 10 2 3 5 4 6 1 2 3 4
Sample Output 1
10
Sample Input 2
6 100 5 10 20 30 15 25 5 1 2 2 3 3 4 4 5 5 6
Sample Output 2
65
Sample Input 3
10 1500000000000 8 100000000000 200000000000 150000000000 300000000000 250000000000 50000000000 400000000000 180000000000 350000000000 120000000000 1 2 2 3 1 5 4 7 4 9 5 6 7 9 8 9
Sample Output 3
1150000000000