A - Product Quality Evaluation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

高橋君は工場の品質管理を担当しています。この工場では N 種類の商品を製造しており、それぞれ 1 から N までの番号が付けられています。

各商品には「品質指数」と「製造数」という 2 つの指標があります。商品 i の品質指数は A_i、1 日あたりの製造数は B_i 個です。品質指数は値が大きいほど不良品が発生しやすいことを表します。

高橋君は、各商品について「リスクスコア」を計算することにしました。商品 i のリスクスコアは、品質指数 A_i と製造数 B_i の積、すなわち A_i \times B_i で定義されます。リスクスコアが高い商品ほど、注意が必要であることを意味します。

高橋君は、リスクスコアが K 以上である商品を重点的に改善する必要があると考えています。リスクスコアが K 以上の商品の数を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^{18}
  • 1 \leq A_i \leq 100 (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 が、スペース区切りで与えられる。
  • 2 行目から N+1 行目では、各商品の情報が与えられる。
  • i+1 行目 (1 \leq i \leq N) では、商品 i の品質指数 A_i と製造数 B_i が、スペース区切りで与えられる。

出力

リスクスコアが K 以上である商品の数を 1 行で出力せよ。


入力例 1

3 100
10 5
20 10
5 30

出力例 1

2

入力例 2

5 500
15 40
8 100
50 20
30 15
25 25

出力例 2

4

Score : 200 pts

Problem Statement

Takahashi is in charge of quality control at a factory. This factory manufactures N types of products, each numbered from 1 to N.

Each product has two metrics: a "quality index" and a "production quantity." The quality index of product i is A_i, and its daily production quantity is B_i units. A higher quality index indicates that defective items are more likely to occur.

Takahashi decided to calculate a "risk score" for each product. The risk score of product i is defined as the product of the quality index A_i and the production quantity B_i, namely A_i \times B_i. A higher risk score means that more attention is required for that product.

Takahashi believes that products with a risk score of K or higher need to be prioritized for improvement. Find the number of products whose risk score is K or higher.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^{18}
  • 1 \leq A_i \leq 100 (1 \leq i \leq N)
  • 1 \leq B_i \leq 10^9 (1 \leq i \leq N)
  • All inputs 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 product types and an integer K representing the risk score threshold, separated by a space.
  • From the 2nd line to the (N+1)-th line, information about each product is given.
  • The (i+1)-th line (1 \leq i \leq N) contains the quality index A_i and the production quantity B_i of product i, separated by a space.

Output

Output the number of products whose risk score is K or higher, in a single line.


Sample Input 1

3 100
10 5
20 10
5 30

Sample Output 1

2

Sample Input 2

5 500
15 40
8 100
50 20
30 15
25 25

Sample Output 2

4
B - Line of Handshakes

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233 点

問題文

高橋君は、パーティー会場で面白い現象を観察しています。

N 人の参加者が一列に、全員同じ方向(右向き)を向いて並んでおり、左から順に 1, 2, \ldots, N と番号が付けられています。各参加者は自分から見た左手と右手にそれぞれ手袋をはめています。手袋の色は紺色または白色のいずれかです。入力では、紺色を N(Navy)、白色を S(Snow)で表します。

> 注意: 手袋の色を表す文字 N(紺色)と、参加者の人数を表す整数 N は異なるものです。混同しないよう注意してください。

参加者 i の左手の手袋の色は L_i、右手の手袋の色は R_i で与えられます。

全員が同じ方向を向いて一列に並んでいるため、隣り合う2人の参加者が握手をするとき、左側の参加者(番号が小さい方)の右手と、右側の参加者(番号が大きい方)の左手が触れ合います。このとき、触れ合う2つの手袋の色が同じ(紺色同士または白色同士)である場合、これを 気まずい握手 と呼びます。

高橋君は、隣り合う参加者のペアのうち、気まずい握手になるペアの数を知りたいと思っています。

具体的には、i = 1, 2, \ldots, N-1 のそれぞれについて、参加者 i の右手の手袋の色 R_i と参加者 i+1 の左手の手袋の色 L_{i+1} が同じであるかを調べ、同じであるような i の個数を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • L_i は N または S (1 \leq i \leq N)
  • R_i は N または S (1 \leq i \leq N)

入力

N
L_1 R_1
L_2 R_2
\vdots
L_N R_N
  • 1 行目には、参加者の人数を表す整数 N が与えられる。
  • 続く N 行のうち i 行目 (1 \leq i \leq N) には、参加者 i の左手の手袋の色を表す文字 L_i と右手の手袋の色を表す文字 R_i が、スペース区切りで与えられる。L_i, R_i はそれぞれ N(紺色)または S(白色)のいずれかである。

出力

気まずい握手になる隣り合う参加者のペアの数を 1 行で出力せよ。


入力例 1

4
N S
S N
N N
S S

出力例 1

2

入力例 2

2
N N
N S

出力例 2

1

入力例 3

10
S S
S N
N S
S S
S N
N N
N S
S S
S N
N N

出力例 3

9

Score : 233 pts

Problem Statement

Takahashi is observing an interesting phenomenon at a party venue.

N participants are standing in a line, all facing the same direction (to the right), and are numbered 1, 2, \ldots, N from left to right. Each participant is wearing a glove on their left hand and right hand (from their own perspective). The color of each glove is either navy or white. In the input, navy is represented by N (Navy) and white is represented by S (Snow).

> Note: The character N representing the navy color and the integer N representing the number of participants are different things. Please be careful not to confuse them.

The color of participant i's left-hand glove is given as L_i, and the color of their right-hand glove is given as R_i.

Since all participants are standing in a line facing the same direction, when two adjacent participants shake hands, the right hand of the left participant (the one with the smaller number) and the left hand of the right participant (the one with the larger number) touch each other. If the colors of the two gloves that touch are the same (both navy or both white), this is called an awkward handshake.

Takahashi wants to know the number of adjacent participant pairs that result in an awkward handshake.

Specifically, for each i = 1, 2, \ldots, N-1, check whether the color of participant i's right-hand glove R_i and the color of participant i+1's left-hand glove L_{i+1} are the same, and find the number of such i.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • L_i is N or S (1 \leq i \leq N)
  • R_i is N or S (1 \leq i \leq N)

Input

N
L_1 R_1
L_2 R_2
\vdots
L_N R_N
  • The first line contains an integer N representing the number of participants.
  • In the following N lines, the i-th line (1 \leq i \leq N) contains the character L_i representing the color of participant i's left-hand glove and the character R_i representing the color of participant i's right-hand glove, separated by a space. Each of L_i and R_i is either N (navy) or S (white).

Output

Print the number of adjacent participant pairs that result in an awkward handshake, in a single line.


Sample Input 1

4
N S
S N
N N
S S

Sample Output 1

2

Sample Input 2

2
N N
N S

Sample Output 2

1

Sample Input 3

10
S S
S N
N S
S S
S N
N N
N S
S S
S N
N N

Sample Output 3

9
C - Bargain Sale Selection

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

高橋君は、 N 個の商品をすべて1個ずつ購入します。

各商品には「通常価格」と「セール価格」の2つの価格が設定されています。商品 i (1 \leq i \leq N) の通常価格は A_i 円、セール価格は B_i 円です。セール価格は通常価格以下であること、すなわち B_i \leq A_i が保証されています。

高橋君は特別な割引クーポンを1枚持っています。このクーポンにより、 N 個の商品の中から K 個以下 の商品を選んで、選んだ商品をセール価格で購入することができます。選ばなかった残りの商品は通常価格で購入します。なお、1つの商品を複数回選ぶことはできず、1個も選ばない(0 個選ぶ)こともできます。

高橋君がセール価格で購入する商品の選び方を最適にしたとき、 N 個の商品の購入金額の合計の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq N
  • 1 \leq B_i \leq A_i \leq 10^9
  • 入力はすべて整数

入力

N K
A_1 B_1
A_2 B_2
\vdots
A_N B_N
  • 1 行目には、商品の個数を表す整数 N と、セール価格で購入できる商品数の上限を表す整数 K が、スペース区切りで与えられる。
  • 続く N 行のうち i 行目 (1 \leq i \leq N) には、商品 i の通常価格 A_i とセール価格 B_i が、スペース区切りで与えられる。

出力

N 個の商品の購入金額の合計の最小値を整数で 1 行に出力せよ。なお、答えは 32 ビット整数の範囲に収まるとは限らないことに注意せよ。


入力例 1

3 2
100 80
200 150
300 250

出力例 1

500

入力例 2

5 3
1000 500
800 800
600 400
900 700
1200 300

出力例 2

2900

入力例 3

7 4
500000000 100000000
300000000 250000000
800000000 200000000
150000000 150000000
600000000 350000000
400000000 100000000
700000000 650000000

出力例 3

1900000000

Score : 300 pts

Problem Statement

Takahashi will purchase all N items, one of each.

Each item has two prices: a "regular price" and a "sale price." The regular price of item i (1 \leq i \leq N) is A_i yen, and the sale price is B_i yen. It is guaranteed that the sale price is at most the regular price, that is, B_i \leq A_i.

Takahashi has one special discount coupon. With this coupon, he can choose at most K items from the N items and purchase the chosen items at their sale prices. The remaining items that are not chosen will be purchased at their regular prices. Note that the same item cannot be chosen more than once, and it is also allowed to choose no items (i.e., choose 0 items).

When Takahashi optimally chooses which items to purchase at the sale price, find the minimum possible total cost of purchasing all N items.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq N
  • 1 \leq B_i \leq A_i \leq 10^9
  • 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 items and an integer K representing the maximum number of items that can be purchased at the sale price, separated by a space.
  • The following N lines each contain, for the i-th line (1 \leq i \leq N), the regular price A_i and the sale price B_i of item i, separated by a space.

Output

Print the minimum possible total cost of purchasing all N items as an integer on a single line. Note that the answer may not fit within a 32-bit integer.


Sample Input 1

3 2
100 80
200 150
300 250

Sample Output 1

500

Sample Input 2

5 3
1000 500
800 800
600 400
900 700
1200 300

Sample Output 2

2900

Sample Input 3

7 4
500000000 100000000
300000000 250000000
800000000 200000000
150000000 150000000
600000000 350000000
400000000 100000000
700000000 650000000

Sample Output 3

1900000000
D - Consecutive Practice Days

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

高橋君は陸上部のマネージャーとして、部員たちの練習記録を管理しています。

陸上部では N 日間の練習期間があり、各日には 1 から N までの番号が付けられています。日 i (1 \leq i \leq N) には、その日の「練習強度」を表す正の整数 A_i が記録されています。

部のルールでは、日 l から日 r までの連続する r - l + 1 日間からなる期間であって、その長さが K 日以上かつ期間内の練習強度の合計が目標値 M 以上であるものを「達成期間」と呼び、特別に表彰することになっています。

高橋君は、表彰対象となる達成期間がいくつあるかを調べたいと考えています。

具体的には、以下の条件をすべて満たす整数の組 (l, r) の個数を求めてください:

  • 1 \leq l \leq r \leq N
  • r - l + 1 \geq K (期間の長さが K 日以上)
  • A_l + A_{l+1} + \cdots + A_r \geq M (期間内の練習強度の合計が M 以上)

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N
  • 1 \leq M \leq 10^{14}
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N K M
A_1 A_2 \cdots A_N
  • 1 行目には、練習期間の日数を表す整数 N、期間の長さの最小値を表す整数 K、練習強度の合計の目標値を表す整数 M が、空白区切りで与えられる。
  • 2 行目には、各日の練習強度を表す N 個の整数 A_1, A_2, \ldots, A_N が、空白区切りで与えられる。

出力

条件を満たす整数の組 (l, r) の個数を 1 行で出力してください。


入力例 1

5 2 10
3 5 4 2 6

出力例 1

6

入力例 2

8 3 15
2 4 6 3 5 7 1 8

出力例 2

17

入力例 3

10 4 1000000000000
500000000 600000000 400000000 300000000 700000000 200000000 800000000 100000000 900000000 550000000

出力例 3

0

Score : 400 pts

Problem Statement

Takahashi is the manager of the track and field club, and he manages the practice records of the club members.

The track and field club has a practice period of N days, and each day is numbered from 1 to N. On day i (1 \leq i \leq N), a positive integer A_i representing the "practice intensity" for that day is recorded.

According to the club's rules, a period consisting of r - l + 1 consecutive days from day l to day r is called an "achievement period" and is specially recognized if its length is at least K days and the total practice intensity within the period is at least the target value M.

Takahashi wants to find out how many achievement periods qualify for recognition.

Specifically, find the number of integer pairs (l, r) that satisfy all of the following conditions:

  • 1 \leq l \leq r \leq N
  • r - l + 1 \geq K (the length of the period is at least K days)
  • A_l + A_{l+1} + \cdots + A_r \geq M (the total practice intensity within the period is at least M)

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N
  • 1 \leq M \leq 10^{14}
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • All input values are integers

Input

N K M
A_1 A_2 \cdots A_N
  • The first line contains an integer N representing the number of days in the practice period, an integer K representing the minimum length of a period, and an integer M representing the target value for the total practice intensity, separated by spaces.
  • The second line contains N integers A_1, A_2, \ldots, A_N representing the practice intensity for each day, separated by spaces.

Output

Print the number of integer pairs (l, r) that satisfy the conditions, on a single line.


Sample Input 1

5 2 10
3 5 4 2 6

Sample Output 1

6

Sample Input 2

8 3 15
2 4 6 3 5 7 1 8

Sample Output 2

17

Sample Input 3

10 4 1000000000000
500000000 600000000 400000000 300000000 700000000 200000000 800000000 100000000 900000000 550000000

Sample Output 3

0
E - Cargo Delivery Truck

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433 点

問題文

高橋君は運送会社で働いています。今日は N 個の荷物を配送センターから届け先へ配送する必要があります。各荷物には 1 から N までの番号が付いており、荷物 i の重さは W_i キログラムです。

配送センターには M 台のトラックがあり、各トラックには 1 から M までの番号が付いています。トラック j の積載重量の上限は C_j キログラムであり、そのトラックに積んだ荷物の重さの合計が C_j キログラムを超えてはなりません。各トラックに積む荷物の個数についての制限はなく、荷物を 1 個も積まないトラックがあっても構いません。

各荷物は分割することができず、必ずちょうど 1 台のトラックに積まなければなりません。すべての N 個の荷物を、積載重量の上限を守りながらトラックに積むことが可能かどうかを判定してください。

制約

  • 1 \leq N \leq 15
  • 1 \leq M \leq 15
  • 1 \leq W_i \leq 10^8 (1 \leq i \leq N)
  • 1 \leq C_j \leq 10^9 (1 \leq j \leq M)
  • 入力はすべて整数

入力

N M
W_1 W_2 \ldots W_N
C_1 C_2 \ldots C_M
  • 1 行目には、荷物の個数を表す N と、トラックの台数を表す M が、空白区切りで与えられる。
  • 2 行目には、各荷物の重さを表す W_1, W_2, \ldots, W_N が、空白区切りで与えられる。
  • 3 行目には、各トラックの積載重量の上限を表す C_1, C_2, \ldots, C_M が、空白区切りで与えられる。

出力

すべての荷物をトラックに積むことが可能であれば Yes を、不可能であれば No を出力してください。


入力例 1

3 2
3 5 2
6 4

出力例 1

No

入力例 2

4 2
10 20 30 40
50 50

出力例 2

Yes

入力例 3

8 3
15 25 30 10 20 35 5 40
80 60 50

出力例 3

Yes

Score : 433 pts

Problem Statement

Takahashi works at a shipping company. Today, he needs to deliver N packages from the distribution center to their destinations. Each package is numbered from 1 to N, and package i weighs W_i kilograms.

The distribution center has M trucks, each numbered from 1 to M. Truck j has a maximum load capacity of C_j kilograms, meaning the total weight of packages loaded onto that truck must not exceed C_j kilograms. There is no limit on the number of packages loaded onto each truck, and it is acceptable for a truck to carry no packages at all.

Each package cannot be split and must be loaded onto exactly one truck. Determine whether it is possible to load all N packages onto the trucks without exceeding any truck's maximum load capacity.

Constraints

  • 1 \leq N \leq 15
  • 1 \leq M \leq 15
  • 1 \leq W_i \leq 10^8 (1 \leq i \leq N)
  • 1 \leq C_j \leq 10^9 (1 \leq j \leq M)
  • All inputs are integers

Input

N M
W_1 W_2 \ldots W_N
C_1 C_2 \ldots C_M
  • The first line contains N, the number of packages, and M, the number of trucks, separated by a space.
  • The second line contains W_1, W_2, \ldots, W_N, the weights of the packages, separated by spaces.
  • The third line contains C_1, C_2, \ldots, C_M, the maximum load capacities of the trucks, separated by spaces.

Output

If it is possible to load all packages onto the trucks, print Yes; otherwise, print No.


Sample Input 1

3 2
3 5 2
6 4

Sample Output 1

No

Sample Input 2

4 2
10 20 30 40
50 50

Sample Output 2

Yes

Sample Input 3

8 3
15 25 30 10 20 35 5 40
80 60 50

Sample Output 3

Yes