Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君は、過去 N 試合の勝敗の記録を調べています。各試合の結果は「勝ち」を表す W または「負け」を表す L のいずれかで記録されています。
高橋君は、この記録の中で最も長く連続して勝利した試合数を知りたいと思っています。
試合数 N と、勝敗を表す長さ N の文字列 S が与えられたとき、S に含まれる W の最長連続部分の長さを求めてください。W が一つも含まれない場合、答えは 0 です。
制約
- 1 \leq N \leq 10^6
- S は
WとLのみからなる長さ N の文字列である。
入力
入力は以下の形式で与えられます。
N S
- 1 行目には、試合数を表す整数 N が与えられる。
- 2 行目には、
WとLのみからなる長さ N の文字列 S が与えられる。
出力
S に含まれる W の最長連続部分の長さを整数で一行に出力してください。
入力例 1
8 WLWWWLLW
出力例 1
3
入力例 2
5 LLLLL
出力例 2
0
入力例 3
20 WWLLWWWWWLWLWWWLLLWW
出力例 3
5
入力例 4
60 LWWWWLWWWLLWWWWWWLWLWWWWLWWLLLLWWWWWWWLWLWWWWWWWWLLLWWLWWWWW
出力例 4
8
入力例 5
1 W
出力例 5
1
Score : 233 pts
Problem Statement
Takahashi is examining the record of wins and losses from his past N matches. The result of each match is recorded as either W representing a "win" or L representing a "loss".
Takahashi wants to know the longest streak of consecutive wins in this record.
Given the number of matches N and a string S of length N representing the wins and losses, find the length of the longest consecutive sequence of W in S. If S contains no W at all, the answer is 0.
Constraints
- 1 \leq N \leq 10^6
- S is a string of length N consisting only of
WandL.
Input
The input is given in the following format.
N S
- The first line contains an integer N representing the number of matches.
- The second line contains a string S of length N consisting only of
WandL.
Output
Print the length of the longest consecutive sequence of W in S as an integer on a single line.
Sample Input 1
8 WLWWWLLW
Sample Output 1
3
Sample Input 2
5 LLLLL
Sample Output 2
0
Sample Input 3
20 WWLLWWWWWLWLWWWLLLWW
Sample Output 3
5
Sample Input 4
60 LWWWWLWWWLLWWWWWWLWLWWWWLWWLLLLWWWWWWWLWLWWWWWWWWLLLWWLWWWWW
Sample Output 4
8
Sample Input 5
1 W
Sample Output 5
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君はサッカーチームの監督をしています。チームには N 人の選手がおり、各選手には 1 から N までの背番号がちょうど 1 つずつ付けられています。高橋君はこの中から K 人をレギュラーメンバーとして選抜しなければなりません。
各選手 i (1 \leq i \leq N) には、練習での評価点 A_i と、直近の試合での評価点 B_i の 2 つのパラメータがあります。選手 i の「総合評価」は A_i + B_i として算出されます。
高橋君は、以下のルールに従って N 人の選手に 1 位から N 位までの順位を付けます。
- 総合評価が大きい選手ほど上位(順位の値が小さい)とする。
- 総合評価が等しい選手同士では、背番号が小さい選手ほど上位とする。
背番号は選手ごとに異なるため、このルールによりすべての選手の順位は一意に定まります。
こうして付けられた順位が 1 位から K 位までの K 人をレギュラーメンバーとして選びます。
レギュラーメンバーに選ばれた K 人の背番号を小さい順に出力してください。
制約
- 1 \leq K \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq B_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数である。
入力
N K A_1 B_1 A_2 B_2 \vdots A_N B_N
- 1 行目には、選手の人数を表す整数 N と、レギュラーメンバーの人数を表す整数 K が、空白区切りで与えられる。
- 1 + i 行目 (1 \leq i \leq N) には、選手 i の練習での評価点 A_i と直近の試合での評価点 B_i が空白区切りで与えられる。
出力
レギュラーメンバーに選ばれた K 人の背番号を小さい順に、1 行に 1 つずつ出力せよ。
入力例 1
5 3 10 20 30 10 20 20 15 25 25 15
出力例 1
2 3 4
入力例 2
6 3 5 5 10 10 10 10 3 7 8 2 1 9
出力例 2
1 2 3
入力例 3
10 4 50 60 80 30 45 55 70 40 60 50 90 20 30 80 100 10 55 45 65 35
出力例 3
1 2 4 5
入力例 4
20 7 500 300 100 900 350 350 700 200 450 550 600 400 250 750 800 100 150 850 400 500 550 450 300 600 650 250 200 800 750 150 50 950 900 50 1000 1 1 1000 500 500
出力例 4
2 5 6 7 9 18 19
入力例 5
1 1 1 1
出力例 5
1
Score : 300 pts
Problem Statement
Takahashi is the manager of a soccer team. The team has N players, and each player is assigned exactly one jersey number from 1 to N. Takahashi must select K players from among them as regular members.
Each player i (1 \leq i \leq N) has two parameters: a practice evaluation score A_i and a recent match evaluation score B_i. The "overall evaluation" of player i is calculated as A_i + B_i.
Takahashi ranks all N players from rank 1 to rank N according to the following rules:
- A player with a higher overall evaluation is ranked higher (i.e., has a smaller rank value).
- Among players with equal overall evaluations, the player with the smaller jersey number is ranked higher.
Since jersey numbers are distinct for each player, these rules uniquely determine the rank of every player.
The K players ranked from 1st to Kth are selected as regular members.
Output the jersey numbers of the K players selected as regular members in ascending order.
Constraints
- 1 \leq K \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq B_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers.
Input
N K A_1 B_1 A_2 B_2 \vdots A_N B_N
- The first line contains an integer N representing the number of players and an integer K representing the number of regular members, separated by a space.
- The (1 + i)-th line (1 \leq i \leq N) contains player i's practice evaluation score A_i and recent match evaluation score B_i, separated by a space.
Output
Output the jersey numbers of the K players selected as regular members in ascending order, one per line.
Sample Input 1
5 3 10 20 30 10 20 20 15 25 25 15
Sample Output 1
2 3 4
Sample Input 2
6 3 5 5 10 10 10 10 3 7 8 2 1 9
Sample Output 2
1 2 3
Sample Input 3
10 4 50 60 80 30 45 55 70 40 60 50 90 20 30 80 100 10 55 45 65 35
Sample Output 3
1 2 4 5
Sample Input 4
20 7 500 300 100 900 350 350 700 200 450 550 600 400 250 750 800 100 150 850 400 500 550 450 300 600 650 250 200 800 750 150 50 950 900 50 1000 1 1 1000 500 500
Sample Output 4
2 5 6 7 9 18 19
Sample Input 5
1 1 1 1
Sample Output 5
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は、アルバイト先の店長として、今月のシフト M コマを N 人のスタッフに割り当てようとしています。
各スタッフ i( 1 \leq i \leq N )には、今月働ける上限コマ数 R_i が決まっています。高橋君は、各スタッフへの割り当てコマ数 X_i を、0 \leq X_i \leq R_i を満たす非負整数として決めます。
割り当ては、次の合計条件を満たさなければなりません。
- 合計条件: 割り当てるシフトの合計はちょうど M コマである。すなわち、X_1 + X_2 + \cdots + X_N = M 。
合計条件を満たす割り当てが 1 つ以上存在するとき、高橋君は不公平度をできるだけ小さくしたいと考えています。ここで、各スタッフ i について、上限コマ数と実際の割り当てコマ数の差 R_i - X_i を「スタッフ i の未割り当て枠」と呼びます。全スタッフの未割り当て枠の最大値、すなわち
\max_{1 \leq i \leq N} (R_i - X_i)
を「不公平度」と定義します。
不公平度が大きいということは、上限に対して割り当てが極端に少ないスタッフが存在することを意味します。高橋君は、そのようなスタッフの不満をできるだけ抑えるため、不公平度を最小化したいのです。
合計条件を満たす割り当てが存在するとき、不公平度の最小値を求めてください。合計条件を満たす割り当てが存在しない場合は -1 を出力してください。
なお、合計条件を満たす割り当てが存在しないのは、M > R_1 + R_2 + \cdots + R_N である場合、またその場合に限ります。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 10^{18}
- 0 \leq R_i \leq 10^{18}( 1 \leq i \leq N)
- 入力はすべて整数である。
注意: R_1 + R_2 + \cdots + R_N は 64 ビット符号付き整数の範囲を超える場合があります。
入力
N M R_1 R_2 \cdots R_N
- 1 行目には、スタッフの人数を表す整数 N と、割り当てるシフトの総コマ数を表す整数 M が、スペース区切りで与えられる。
- 2 行目には、各スタッフの上限コマ数を表す整数 R_1, R_2, \ldots, R_N が、スペース区切りで与えられる。
出力
不公平度の最小値を 1 行で出力してください。合計条件を満たす割り当てが存在しない場合は -1 を出力してください。
入力例 1
3 7 4 3 5
出力例 1
2
入力例 2
3 20 5 5 5
出力例 2
-1
入力例 3
5 1000000000000000000 300000000000000000 200000000000000000 400000000000000000 100000000000000000 500000000000000000
出力例 3
100000000000000000
Score : 366 pts
Problem Statement
Takahashi, as the manager of his part-time workplace, is trying to assign this month's M shift slots to N staff members.
Each staff member i (1 \leq i \leq N) has a predetermined maximum number of slots R_i they can work this month. Takahashi determines the number of slots X_i assigned to each staff member as a non-negative integer satisfying 0 \leq X_i \leq R_i.
The assignment must satisfy the following total condition:
- Total condition: The total number of assigned shifts is exactly M slots. That is, X_1 + X_2 + \cdots + X_N = M.
When at least one assignment satisfying the total condition exists, Takahashi wants to minimize the unfairness. Here, for each staff member i, the difference R_i - X_i between their maximum slots and their actually assigned slots is called the "unassigned capacity of staff member i". The maximum unassigned capacity across all staff members, namely
\max_{1 \leq i \leq N} (R_i - X_i)
is defined as the "unfairness".
A large unfairness means that there exists a staff member whose assignment is extremely small relative to their maximum. Takahashi wants to minimize the unfairness in order to reduce the dissatisfaction of such staff members as much as possible.
When an assignment satisfying the total condition exists, find the minimum value of the unfairness. If no assignment satisfying the total condition exists, output -1.
Note that an assignment satisfying the total condition does not exist if and only if M > R_1 + R_2 + \cdots + R_N.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq 10^{18}
- 0 \leq R_i \leq 10^{18} (1 \leq i \leq N)
- All input values are integers.
Note: R_1 + R_2 + \cdots + R_N may exceed the range of a 64-bit signed integer.
Input
N M R_1 R_2 \cdots R_N
- The first line contains an integer N representing the number of staff members and an integer M representing the total number of shift slots to assign, separated by a space.
- The second line contains integers R_1, R_2, \ldots, R_N representing the maximum number of slots for each staff member, separated by spaces.
Output
Output the minimum value of the unfairness in one line. If no assignment satisfying the total condition exists, output -1.
Sample Input 1
3 7 4 3 5
Sample Output 1
2
Sample Input 2
3 20 5 5 5
Sample Output 2
-1
Sample Input 3
5 1000000000000000000 300000000000000000 200000000000000000 400000000000000000 100000000000000000 500000000000000000
Sample Output 3
100000000000000000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は冒険者としてダンジョンに挑もうとしています。手持ちの装備品は全部で N 個あり、i 番目の装備品(i = 1, 2, \ldots, N)の防御力は W_i、攻撃力は S_i です。
今回挑むダンジョンは非常に危険で、身につけた装備品の防御力の合計が K 以上でなければ入場することができません。高橋君は N 個の装備品の中から 0 個以上 N 個以下の装備品を選んで身につけることができます。ただし、同じ装備品を 2 回以上選ぶことはできません。
高橋君は、選んだ装備品の防御力の合計が K 以上になるような選び方のうち、攻撃力の合計が最大となるようにしたいです。
防御力の合計が K 以上となる選び方が存在する場合は、攻撃力の合計の最大値を出力してください。そのような選び方が存在しない場合は -1 を出力してください。
制約
- 1 \leq N \leq 100
- 1 \leq K \leq 10^4
- 1 \leq W_i \leq 10^4
- 1 \leq S_i \leq 10^5
- 入力はすべて整数である
入力
N K W_1 S_1 W_2 S_2 \vdots W_N S_N
- 1 行目には、装備品の数 N と、必要な防御力の合計の下限 K が、スペース区切りで与えられる。
- 続く N 行の i 行目(i = 1, 2, \ldots, N)には、i 番目の装備品の防御力 W_i と攻撃力 S_i が、スペース区切りで与えられる。
出力
防御力の合計が K 以上となる装備品の選び方が存在する場合は、攻撃力の合計の最大値を 1 行で出力せよ。存在しない場合は -1 を 1 行で出力せよ。
入力例 1
4 5 3 8 1 3 3 7 2 2
出力例 1
20
入力例 2
3 50 6 100 8 200 5 150
出力例 2
-1
入力例 3
10 30 5 80 1 10 8 90 4 50 6 70 3 40 2 30 7 60 9 50 10 50
出力例 3
530
Score : 400 pts
Problem Statement
Takahashi is an adventurer about to challenge a dungeon. He has a total of N pieces of equipment, where the i-th piece of equipment (i = 1, 2, \ldots, N) has a defense power of W_i and an attack power of S_i.
The dungeon he is about to challenge is extremely dangerous, and he cannot enter unless the total defense power of his equipped items is at least K. Takahashi can choose and equip anywhere from 0 to N pieces of equipment out of the N available. However, the same piece of equipment cannot be chosen more than once.
Among all ways to choose equipment such that the total defense power is at least K, Takahashi wants to maximize the total attack power.
If there exists a selection of equipment whose total defense power is at least K, output the maximum total attack power. If no such selection exists, output -1.
Constraints
- 1 \leq N \leq 100
- 1 \leq K \leq 10^4
- 1 \leq W_i \leq 10^4
- 1 \leq S_i \leq 10^5
- All input values are integers
Input
N K W_1 S_1 W_2 S_2 \vdots W_N S_N
- The first line contains the number of pieces of equipment N and the minimum required total defense power K, separated by a space.
- The following N lines each contain, on the i-th line (i = 1, 2, \ldots, N), the defense power W_i and attack power S_i of the i-th piece of equipment, separated by a space.
Output
If there exists a selection of equipment whose total defense power is at least K, output the maximum total attack power on a single line. If no such selection exists, output -1 on a single line.
Sample Input 1
4 5 3 8 1 3 3 7 2 2
Sample Output 1
20
Sample Input 2
3 50 6 100 8 200 5 150
Sample Output 2
-1
Sample Input 3
10 30 5 80 1 10 8 90 4 50 6 70 3 40 2 30 7 60 9 50 10 50
Sample Output 3
530
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 433 点
問題文
高橋君は庭園にある石畳の小道を歩いています。小道には N 個の飛び石が一列に並んでおり、左から順に 1, 2, \ldots, N と番号が付けられています。各飛び石 i には景観の評価を表すスコア A_i が設定されています。スコアは負の値をとることもあります。
高橋君は飛び石 1 からスタートし、飛び石 N まで移動します。現在飛び石 i にいるとき、次のいずれかの行動を取ることができます:
- 一歩進む:飛び石 i + 1 に移動する(i + 1 \leq N の場合のみ)。
- 一つ飛ばしで跳ぶ:飛び石 i + 1 を飛び越え、そこには立ち寄らずに飛び石 i + 2 に移動する(i + 2 \leq N の場合のみ)。
「一つ飛ばしで跳ぶ」動作は体力を消耗するため、飛び石 1 から飛び石 N までの移動を通して最大 K 回までしか行えません(0 回でも構いません)。「一歩進む」動作の回数に制限はありません。
高橋君は飛び石 N に到達した時点で移動を終了します。移動の過程で高橋君が訪れた飛び石すべて(出発地点の飛び石 1 および到達地点の飛び石 N を含む)のスコアの合計を最大化してください。その最大値を求めてください。
なお、「一つ飛ばしで跳ぶ」動作を一切使わず、すべて「一歩進む」で移動すれば必ず飛び石 N に到達できるため、条件を満たす移動方法は常に存在します。
制約
- 2 \leq N \leq 2 \times 10^5
- 0 \leq K \leq N
- -10^9 \leq A_i \leq 10^9
- 入力はすべて整数である。
入力
N K A_1 A_2 \ldots A_N
- 1 行目には、飛び石の個数を表す整数 N と、「一つ飛ばしで跳ぶ」動作の最大回数を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各飛び石のスコアを表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
高橋君が飛び石 1 から飛び石 N まで移動するとき、訪れた飛び石のスコアの合計の最大値を 1 行で出力せよ。
入力例 1
5 1 3 -5 4 -2 6
出力例 1
11
入力例 2
4 0 -1 2 -3 4
出力例 2
2
入力例 3
12 3 5 -10 8 -3 7 -20 4 6 -2 9 -15 10
出力例 3
44
入力例 4
30 10 12 -5 7 -100 20 3 -8 15 -30 6 9 -2 -50 25 4 -1 18 -40 11 13 -7 5 -60 30 2 -3 16 -20 8 10
出力例 4
211
入力例 5
2 2 -1000000000 -1000000000
出力例 5
-2000000000
Score : 433 pts
Problem Statement
Takahashi is walking along a stone-paved path in a garden. The path has N stepping stones arranged in a row, numbered 1, 2, \ldots, N from left to right. Each stepping stone i has a score A_i representing its scenic evaluation. Scores can be negative.
Takahashi starts at stepping stone 1 and moves to stepping stone N. When currently on stepping stone i, he can take one of the following actions:
- Step forward: Move to stepping stone i + 1 (only if i + 1 \leq N).
- Skip one stone: Jump over stepping stone i + 1 without visiting it, and move to stepping stone i + 2 (only if i + 2 \leq N).
Since the "skip one stone" action is physically exhausting, it can be performed at most K times throughout the entire journey from stepping stone 1 to stepping stone N (it is also fine to use it 0 times). There is no limit on the number of "step forward" actions.
Takahashi ends his journey upon reaching stepping stone N. Maximize the total score of all stepping stones that Takahashi visits during his journey (including the starting stone 1 and the destination stone N). Find this maximum value.
Note that by using only "step forward" actions without any "skip one stone" actions, Takahashi can always reach stepping stone N, so a valid way of moving always exists.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 0 \leq K \leq N
- -10^9 \leq A_i \leq 10^9
- All input values are integers.
Input
N K A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of stepping stones and an integer K representing the maximum number of "skip one stone" actions, separated by a space.
- The second line contains integers A_1, A_2, \ldots, A_N representing the scores of each stepping stone, separated by spaces.
Output
Print in one line the maximum total score of the stepping stones visited when Takahashi moves from stepping stone 1 to stepping stone N.
Sample Input 1
5 1 3 -5 4 -2 6
Sample Output 1
11
Sample Input 2
4 0 -1 2 -3 4
Sample Output 2
2
Sample Input 3
12 3 5 -10 8 -3 7 -20 4 6 -2 9 -15 10
Sample Output 3
44
Sample Input 4
30 10 12 -5 7 -100 20 3 -8 15 -30 6 9 -2 -50 25 4 -1 18 -40 11 13 -7 5 -60 30 2 -3 16 -20 8 10
Sample Output 4
211
Sample Input 5
2 2 -1000000000 -1000000000
Sample Output 5
-2000000000