Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は学校の先生から、テストの採点結果を集計する仕事を頼まれました。
このテストでは、基準点 S 点と許容差 T 点が設定されています。生徒の点数 A_i と基準点 S の差の絶対値が T 以下、すなわち |A_i - S| \leq T であれば、その生徒は「合格」と判定されます。
N 人の生徒がテストを受け、i 番目の生徒 (1 \leq i \leq N) の点数は A_i 点でした。
合格した生徒の人数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq S \leq 100
- 0 \leq T \leq 100
- 0 \leq A_i \leq 100 (1 \leq i \leq N)
- 入力はすべて整数
入力
N S T A_1 A_2 \ldots A_N
- 1 行目には、生徒の人数を表す N 、基準点を表す S 、許容差を表す T が、スペース区切りで与えられる。
- 2 行目には、各生徒の点数を表す A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
- A_i は i 番目の生徒の点数を表す。
出力
合格した生徒の人数を 1 行で出力せよ。
入力例 1
5 60 10 55 70 62 45 58
出力例 1
4
入力例 2
8 75 5 80 75 70 68 82 74 76 90
出力例 2
5
入力例 3
15 50 0 50 49 51 50 48 52 50 50 47 53 50 46 54 50 55
出力例 3
6
Score : 200 pts
Problem Statement
Takahashi has been asked by his school teacher to compile the grading results of a test.
For this test, a reference score of S points and a tolerance of T points are set. If the absolute difference between a student's score A_i and the reference score S is at most T, that is, if |A_i - S| \leq T, then the student is judged as "passing."
N students took the test, and the score of the i-th student (1 \leq i \leq N) was A_i points.
Find the number of students who passed.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq S \leq 100
- 0 \leq T \leq 100
- 0 \leq A_i \leq 100 (1 \leq i \leq N)
- All inputs are integers
Input
N S T A_1 A_2 \ldots A_N
- The first line contains N representing the number of students, S representing the reference score, and T representing the tolerance, separated by spaces.
- The second line contains A_1, A_2, \ldots, A_N representing each student's score, separated by spaces.
- A_i represents the score of the i-th student.
Output
Print the number of students who passed in one line.
Sample Input 1
5 60 10 55 70 62 45 58
Sample Output 1
4
Sample Input 2
8 75 5 80 75 70 68 82 74 76 90
Sample Output 2
5
Sample Input 3
15 50 0 50 49 51 50 48 52 50 50 47 53 50 46 54 50 55
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君は学校の先生で、クラスの委員長選出を担当しています。クラスには N 人の生徒が所属しており、各生徒には 1 から N までの出席番号が付けられています。生徒 i のリーダーシップ点数は A_i です。
現在、出席番号 1 の生徒が暫定的にクラス委員長として登録されています。高橋君は、現在の委員長以外の生徒の中に現在の委員長よりもリーダーシップ点数が真に大きい生徒がいる場合、委員長を変更します。
具体的には、高橋君は以下のルールに従います:
- 現在の委員長(出席番号 1 の生徒)よりもリーダーシップ点数が真に大きい生徒が 1 人以上存在する場合、それらの生徒の中で最もリーダーシップ点数が高い生徒を新しい委員長に指名します。最もリーダーシップ点数が高い生徒が複数いる場合は、その中で出席番号が最も小さい生徒を選びます。
- 現在の委員長よりもリーダーシップ点数が真に大きい生徒が存在しない場合、委員長の変更は行いません。
高橋君が委員長の変更を行った場合は新しい委員長の出席番号を、変更を行わなかった場合は -1 を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
N A_1 A_2 \ldots A_N
- 1 行目には、生徒の人数を表す整数 N が与えられる。
- 2 行目には、各生徒のリーダーシップ点数を表す整数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。A_i は出席番号 i の生徒のリーダーシップ点数である。
出力
委員長の変更を行った場合は新しい委員長の出席番号を、変更を行わなかった場合は -1 を 1 行で出力せよ。
入力例 1
5 3 7 5 7 2
出力例 1
2
入力例 2
4 10 5 8 3
出力例 2
-1
入力例 3
10 50 120 80 120 90 150 150 30 100 75
出力例 3
6
Score : 233 pts
Problem Statement
Takahashi is a school teacher in charge of selecting the class representative. There are N students in the class, and each student is assigned an attendance number from 1 to N. The leadership score of student i is A_i.
Currently, the student with attendance number 1 is provisionally registered as the class representative. Takahashi will change the representative if there exists a student other than the current representative whose leadership score is strictly greater than that of the current representative.
Specifically, Takahashi follows the rules below:
- If there exists one or more students whose leadership score is strictly greater than that of the current representative (the student with attendance number 1), the student with the highest leadership score among them is appointed as the new representative. If there are multiple students with the highest leadership score, the one with the smallest attendance number is chosen.
- If there is no student whose leadership score is strictly greater than that of the current representative, the representative is not changed.
If Takahashi changed the representative, output the attendance number of the new representative. If no change was made, output -1.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq A_i \leq 10^9
- All inputs are integers.
Input
N A_1 A_2 \ldots A_N
- The first line contains an integer N, representing the number of students.
- The second line contains integers A_1, A_2, \ldots, A_N separated by spaces, representing the leadership scores of each student. A_i is the leadership score of the student with attendance number i.
Output
If the representative was changed, output the attendance number of the new representative. If no change was made, output -1 on a single line.
Sample Input 1
5 3 7 5 7 2
Sample Output 1
2
Sample Input 2
4 10 5 8 3
Sample Output 2
-1
Sample Input 3
10 50 120 80 120 90 150 150 30 100 75
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は、N 個の基地局を使って無線ネットワークを構築しようとしています。基地局には 1 から N までの番号が付けられています。基地局は数直線上に設置されており、基地局 i は座標 X_i に位置しています。なお、どの 2 つの基地局も異なる座標に設置されています。
各基地局には同じ通信可能距離 K を持つ無線機器が設置されます。ここで K は非負整数です。2 つの基地局 i, j は、それらの間の距離が K 以下、すなわち |X_i - X_j| \leq K であるとき、直接通信が可能です。
高橋君は、任意の異なる 2 つの基地局の間で、直接通信または他の基地局を 1 つ以上中継することによって通信が可能であるようなネットワークを構築したいと考えています。より正確には、任意の異なる 2 つの基地局 s, t に対して、基地局の列 s = v_1, v_2, \ldots, v_m = t(m \geq 2)が存在し、連続する v_k と v_{k+1}(1 \leq k \leq m-1)がそれぞれ直接通信可能であるようにしたいということです。なお、N = 1 のときは基地局が 1 つしかないため、この条件は K の値によらず常に満たされます。
無線機器のコストを抑えるため、高橋君は通信可能距離 K をできるだけ小さくしたいと思っています。
すべての基地局の座標は整数であるため、条件を満たす K の最小値も必ず非負整数となります。この最小値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq X_i \leq 10^9
- X_i \neq X_j (i \neq j)
- 入力はすべて整数
入力
N X_1 X_2 \ldots X_N
- 1 行目には、基地局の個数を表す整数 N が与えられる。
- 2 行目には、各基地局の座標を表す N 個の整数 X_1, X_2, \ldots, X_N がスペース区切りで与えられる。
出力
すべての基地局間で互いに通信できるようになるための K の最小値を、1 行で出力せよ。
入力例 1
3 1 5 3
出力例 1
2
入力例 2
5 10 25 15 40 30
出力例 2
10
入力例 3
8 100 350 200 550 700 900 450 1000
出力例 3
200
Score : 300 pts
Problem Statement
Takahashi is trying to build a wireless network using N base stations. The base stations are numbered from 1 to N. The base stations are placed on a number line, and base station i is located at coordinate X_i. No two base stations are placed at the same coordinate.
Each base station is equipped with a wireless device that has the same communication range K, where K is a non-negative integer. Two base stations i and j can communicate directly if the distance between them is at most K, that is, |X_i - X_j| \leq K.
Takahashi wants to build a network such that any two distinct base stations can communicate, either directly or by relaying through one or more other base stations. More precisely, for any two distinct base stations s and t, there should exist a sequence of base stations s = v_1, v_2, \ldots, v_m = t (m \geq 2) such that consecutive stations v_k and v_{k+1} (1 \leq k \leq m-1) can each communicate directly. Note that when N = 1, there is only one base station, so this condition is always satisfied regardless of the value of K.
To reduce the cost of the wireless devices, Takahashi wants to make the communication range K as small as possible.
Since all base station coordinates are integers, the minimum value of K that satisfies the condition is guaranteed to be a non-negative integer. Find this minimum value.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq X_i \leq 10^9
- X_i \neq X_j (i \neq j)
- All input values are integers
Input
N X_1 X_2 \ldots X_N
- The first line contains an integer N, representing the number of base stations.
- The second line contains N integers X_1, X_2, \ldots, X_N separated by spaces, representing the coordinates of each base station.
Output
Print in one line the minimum value of K required for all base stations to be able to communicate with each other.
Sample Input 1
3 1 5 3
Sample Output 1
2
Sample Input 2
5 10 25 15 40 30
Sample Output 2
10
Sample Input 3
8 100 350 200 550 700 900 450 1000
Sample Output 3
200
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君はアルバイト先の店長として、シフト管理を担当しています。
今後 N 日間の営業についてシフトを組む必要があります。各営業日には 1, 2, \ldots, N と番号が付けられており、営業日 i (1 \leq i \leq N) には、必要スキルレベル H_i と売上見込み S_i が設定されています。
高橋君の店には M 人のアルバイトが在籍しており、各アルバイト j (1 \leq j \leq M) にはスキルレベル P_j が決まっています。アルバイト j を営業日 i に割り当てるには、H_i \leq P_j を満たす必要があります。つまり、その日の必要スキルレベル以上のスキルを持つアルバイトのみ割り当てることができます。
高橋君は M 人のアルバイト全員をそれぞれ異なる営業日に割り当てたいと考えています。M \leq N であるため、アルバイトが割り当てられない営業日が存在することもあります。具体的には、割り当ては以下の条件をすべて満たす必要があります。
- 各アルバイトはちょうど 1 つの営業日に割り当てられる。すなわち、M 人全員がいずれかの営業日に割り当てられ、割り当てられない人はいない。
- 各営業日に割り当てられるアルバイトは高々 1 人である。すなわち、同じ営業日に 2 人以上のアルバイトが割り当てられることはない。
- アルバイト j が営業日 i に割り当てられるならば、H_i \leq P_j でなければならない。
アルバイトが割り当てられた営業日についてのみ、その売上見込みが得られるものとします。すなわち、ある割り当て方においてアルバイトが割り当てられた営業日の集合を T としたとき、その割り当て方における 売上の合計 は \displaystyle\sum_{i \in T} S_i です。
上記の条件を満たすようにすべてのアルバイトを割り当てることが可能かどうかを判定してください。可能な場合は、条件を満たすすべての割り当て方の中での売上の合計の最大値を求めてください。不可能な場合は -1 を出力してください。
制約
- 1 \leq M \leq N \leq 2 \times 10^5
- 1 \leq H_i \leq 10^9
- 1 \leq S_i \leq 10^9
- 1 \leq P_j \leq 10^9
- 入力はすべて整数
- H_i, S_i, P_j の値は、同じ種類の変数間でも異なる種類の変数間でも重複することがある
入力
N M H_1 S_1 H_2 S_2 \vdots H_N S_N P_1 P_2 \ldots P_M
- 1 行目には、営業日数を表す整数 N と、アルバイトの人数を表す整数 M が、スペース区切りで与えられる。
- 続く N 行のうち i 行目 (1 \leq i \leq N) には、営業日 i の必要スキルレベル H_i と売上見込み S_i がスペース区切りで与えられる。
- 最後の行には、各アルバイトのスキルレベル P_1, P_2, \ldots, P_M がスペース区切りで与えられる。
出力
すべてのアルバイトを条件を満たすようにそれぞれ異なる営業日に割り当てることが可能な場合は、売上の合計の最大値を 1 行で出力せよ。不可能な場合は -1 を出力せよ。
入力例 1
5 3 3 100 5 200 2 150 4 80 1 50 4 3 2
出力例 1
330
入力例 2
4 3 5 100 5 200 5 300 5 400 3 4 2
出力例 2
-1
入力例 3
8 5 10 500 7 300 15 800 5 200 12 600 3 100 8 450 20 1000 8 12 5 15 10
出力例 3
2550
Score : 400 pts
Problem Statement
Takahashi is in charge of shift management as the store manager at his part-time workplace.
He needs to create a shift schedule for the upcoming N business days. Each business day is numbered 1, 2, \ldots, N, and business day i (1 \leq i \leq N) has a required skill level H_i and an expected sales amount S_i.
Takahashi's store has M part-time workers, and each worker j (1 \leq j \leq M) has a skill level P_j. To assign worker j to business day i, the condition H_i \leq P_j must be satisfied. In other words, only workers whose skill level is at least the required skill level for that day can be assigned to it.
Takahashi wants to assign all M part-time workers to distinct business days. Since M \leq N, there may be business days with no worker assigned. Specifically, the assignment must satisfy all of the following conditions:
- Each worker is assigned to exactly 1 business day. That is, all M workers are assigned to some business day, and no one is left unassigned.
- At most 1 worker is assigned to each business day. That is, no business day has 2 or more workers assigned to it.
- If worker j is assigned to business day i, then H_i \leq P_j must hold.
The expected sales are obtained only for business days that have a worker assigned. That is, if the set of business days with assigned workers in a certain assignment is T, then the total sales for that assignment is \displaystyle\sum_{i \in T} S_i.
Determine whether it is possible to assign all workers in a way that satisfies the above conditions. If it is possible, find the maximum total sales among all valid assignments. If it is impossible, output -1.
Constraints
- 1 \leq M \leq N \leq 2 \times 10^5
- 1 \leq H_i \leq 10^9
- 1 \leq S_i \leq 10^9
- 1 \leq P_j \leq 10^9
- All inputs are integers
- The values of H_i, S_i, P_j may coincide, both among variables of the same type and among variables of different types
Input
N M H_1 S_1 H_2 S_2 \vdots H_N S_N P_1 P_2 \ldots P_M
- The first line contains an integer N representing the number of business days and an integer M representing the number of part-time workers, separated by a space.
- The following N lines, where line i (1 \leq i \leq N), contain the required skill level H_i and expected sales S_i for business day i, separated by a space.
- The last line contains the skill levels P_1, P_2, \ldots, P_M of each part-time worker, separated by spaces.
Output
If it is possible to assign all workers to distinct business days satisfying the conditions, output the maximum total sales in one line. If it is impossible, output -1.
Sample Input 1
5 3 3 100 5 200 2 150 4 80 1 50 4 3 2
Sample Output 1
330
Sample Input 2
4 3 5 100 5 200 5 300 5 400 3 4 2
Sample Output 2
-1
Sample Input 3
8 5 10 500 7 300 15 800 5 200 12 600 3 100 8 450 20 1000 8 12 5 15 10
Sample Output 3
2550
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 433 点
問題文
高橋君は、N 個の整数からなる数列 A_1, A_2, \ldots, A_N を持っています。
高橋君は、この数列から連続する区間を 1 つ選びたいと考えています。具体的には、整数の組 (l, r)(1 \leq l \leq r \leq N)を 1 つ選び、l 番目から r 番目までの要素を取り出します。
このとき、選んだ区間のスコアを次のように定義します。
f(l, r) = \sum_{i=l}^{r} A_i + (r - l + 1) \times M
すなわち、区間に含まれる要素の合計に、区間の長さ (r - l + 1) と正の整数 M の積を加えた値です。
スコアが K 以下となるような整数の組 (l, r)(1 \leq l \leq r \leq N)の個数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 10^9
- 1 \leq K \leq 10^{18}
- -10^9 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数
入力
N M K A_1 A_2 \cdots A_N
- 1 行目には、数列の長さ N、スコアの係数 M、スコアの上限 K が、スペース区切りで与えられる。
- 2 行目には、数列の各要素 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
スコアが K 以下となる整数の組 (l, r)(1 \leq l \leq r \leq N)の個数を 1 行で出力してください。
入力例 1
5 2 10 1 3 2 4 1
出力例 1
9
入力例 2
7 3 20 -2 5 -1 4 3 -3 2
出力例 2
22
入力例 3
10 1000000000 5000000000 100 -500 300 200 -100 400 -200 150 250 -50
出力例 3
35
Score : 433 pts
Problem Statement
Takahashi has a sequence of N integers A_1, A_2, \ldots, A_N.
Takahashi wants to select one contiguous interval from this sequence. Specifically, he chooses a pair of integers (l, r) (1 \leq l \leq r \leq N) and extracts the elements from the l-th to the r-th.
The score of the chosen interval is defined as follows:
f(l, r) = \sum_{i=l}^{r} A_i + (r - l + 1) \times M
That is, the score is the sum of the elements in the interval plus the product of the interval length (r - l + 1) and a positive integer M.
Find the number of integer pairs (l, r) (1 \leq l \leq r \leq N) such that the score is at most K.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 10^9
- 1 \leq K \leq 10^{18}
- -10^9 \leq A_i \leq 10^9 (1 \leq i \leq N)
- All inputs are integers.
Input
N M K A_1 A_2 \cdots A_N
- The first line contains the length of the sequence N, the score coefficient M, and the score upper bound K, separated by spaces.
- The second line contains the elements of the sequence A_1, A_2, \ldots, A_N, separated by spaces.
Output
Print in one line the number of integer pairs (l, r) (1 \leq l \leq r \leq N) such that the score is at most K.
Sample Input 1
5 2 10 1 3 2 4 1
Sample Output 1
9
Sample Input 2
7 3 20 -2 5 -1 4 3 -3 2
Sample Output 2
22
Sample Input 3
10 1000000000 5000000000 100 -500 300 200 -100 400 -200 150 250 -50
Sample Output 3
35