A - Number of Successful Applicants

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は学校の期末テストの採点を終えたところです。このテストには N 人の生徒が受験しており、各生徒には 1 から N までの出席番号が振られています。

学校の規定では、テストの得点が K 点以上の生徒は合格となり、追試を免除されます。K 点未満の生徒は不合格となり、追試を受けなければなりません。

出席番号 i の生徒のテストの得点は S_i 点です。

高橋君は、合格した生徒の人数を知りたいと思っています。テストで K 点以上の得点を獲得した生徒の人数を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq 100
  • 0 \leq S_i \leq 100 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N K
S_1 S_2 \ldots S_N
  • 1 行目には、生徒の人数を表す整数 N と、合格の基準点を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各生徒のテストの得点を表す整数 S_1, S_2, \ldots, S_N が、スペース区切りで与えられる。

出力

合格した生徒の人数を 1 行で出力せよ。


入力例 1

5 60
72 45 60 88 59

出力例 1

3

入力例 2

10 50
100 49 50 0 75 50 33 82 51 48

出力例 2

6

入力例 3

20 70
65 70 82 55 91 70 43 88 69 71 100 0 45 78 62 95 70 68 84 50

出力例 3

11

Score : 200 pts

Problem Statement

Takahashi has just finished grading the school's final exam. N students took this exam, and each student is assigned an attendance number from 1 to N.

According to the school's regulations, students who scored K points or more on the exam pass and are exempt from the makeup exam. Students who scored less than K points fail and must take the makeup exam.

The score of the student with attendance number i is S_i points.

Takahashi wants to know the number of students who passed. Find the number of students who scored K points or more on the exam.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq 100
  • 0 \leq S_i \leq 100 (1 \leq i \leq N)
  • All inputs are integers

Input

N K
S_1 S_2 \ldots S_N
  • The first line contains an integer N representing the number of students and an integer K representing the passing score threshold, separated by a space.
  • The second line contains integers S_1, S_2, \ldots, S_N representing each student's exam score, separated by spaces.

Output

Print the number of students who passed on a single line.


Sample Input 1

5 60
72 45 60 88 59

Sample Output 1

3

Sample Input 2

10 50
100 49 50 0 75 50 33 82 51 48

Sample Output 2

6

Sample Input 3

20 70
65 70 82 55 91 70 43 88 69 71 100 0 45 78 62 95 70 68 84 50

Sample Output 3

11
B - Cheerful Support Message

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233

問題文

高橋君は、学校の文化祭で応援メッセージボードを設置しました。

このボードでは、来場者が出演者への応援メッセージを書き込むことができます。高橋君は、文化祭の盛り上がりを分析するため、「元気な応援メッセージ」の数を数えたいと考えています。

「元気な応援メッセージ」とは、そのメッセージの文字列中に含まれる感嘆符 ! の個数が K 個以上であるメッセージのことを指します。

N 人の来場者がそれぞれ 1 つずつ応援メッセージを書き込みました。各来場者のメッセージは英小文字、英大文字、数字、および感嘆符からなる文字列として与えられます。「元気な応援メッセージ」がいくつあるかを求めてください。

制約

  • 1 \leq N \leq 10^4
  • 1 \leq K \leq 10^3
  • 1 \leq |S_i| \leq 10^3|S_i| は文字列 S_i の長さを表す)
  • S_i は英小文字(az)、英大文字(AZ)、数字(09)、および感嘆符(!)のみからなる(空白は含まれない)
  • N, K は整数

入力

N K
S_1
S_2
\vdots
S_N

1 行目には、来場者の人数を表す整数 N と、「元気な応援メッセージ」の基準となる感嘆符の個数を表す整数 K が、スペース区切りで与えられる。

続く N 行のうち i 行目(1 \leq i \leq N)には、i 番目の来場者のメッセージを表す文字列 S_i1 つ与えられる。

出力

「元気な応援メッセージ」の個数を 1 行で出力してください。


入力例 1

3 2
Hello!
Great!!Work!!
Nice

出力例 1

1

入力例 2

5 3
Ganbare!!!
Good!Luck!
Wonderful!!!!!
Fight!
BestWishes!!!YouCanDoIt!!!

出力例 2

3

入力例 3

8 4
Amazing!Performance!
Bravo!!!!
You!Are!The!Best!
Super!!!
Fantastic!!!!!!!!
Keep!Going!
Excellent!Work!Everyone!Cheers!
WOW!!

出力例 3

4

Score : 233 pts

Problem Statement

Takahashi set up a cheer message board at his school's cultural festival.

On this board, visitors can write cheer messages for the performers. Takahashi wants to count the number of "energetic cheer messages" in order to analyze the excitement of the cultural festival.

An "energetic cheer message" is a message whose string contains K or more exclamation marks !.

N visitors each wrote exactly one cheer message. Each visitor's message is given as a string consisting of lowercase English letters, uppercase English letters, digits, and exclamation marks. Determine how many "energetic cheer messages" there are.

Constraints

  • 1 \leq N \leq 10^4
  • 1 \leq K \leq 10^3
  • 1 \leq |S_i| \leq 10^3 (|S_i| denotes the length of string S_i)
  • S_i consists only of lowercase English letters (az), uppercase English letters (AZ), digits (09), and exclamation marks (!) (no spaces are included)
  • N, K are integers

Input

N K
S_1
S_2
\vdots
S_N

The first line contains two integers separated by a space: N, the number of visitors, and K, the threshold number of exclamation marks for an "energetic cheer message".

For each of the following N lines, the i-th line (1 \leq i \leq N) contains a single string S_i representing the message of the i-th visitor.

Output

Print the number of "energetic cheer messages" on a single line.


Sample Input 1

3 2
Hello!
Great!!Work!!
Nice

Sample Output 1

1

Sample Input 2

5 3
Ganbare!!!
Good!Luck!
Wonderful!!!!!
Fight!
BestWishes!!!YouCanDoIt!!!

Sample Output 2

3

Sample Input 3

8 4
Amazing!Performance!
Bravo!!!!
You!Are!The!Best!
Super!!!
Fantastic!!!!!!!!
Keep!Going!
Excellent!Work!Everyone!Cheers!
WOW!!

Sample Output 3

4
C - Consecutive Card Distribution

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君はカードゲームの大会を運営しています。

大会には N 枚のカードが使用されます。カード i1 \leq i \leq N)には正の整数 A_i が書かれており、N 枚のカードに書かれた整数はすべて異なります。

高橋君は、これらの N 枚のカードすべてをいくつかのグループに分けたいと考えています。ただし、各カードはちょうど 1 つのグループに属さなければならず、どのグループにも 1 枚以上のカードが含まれていなければなりません。さらに、各グループは以下で定義される「連番グループ」でなければなりません。

あるカードの集合が連番グループであるとは、そこに含まれるカードに書かれた整数を集めた集合が、ある整数 a と正の整数 k を用いて \{a, a+1, a+2, \ldots, a+k-1\} と表せることを指します。すなわち、連続する k 個の整数からなる集合です。k = 1 の場合、すなわちカード 1 枚だけからなるグループも連番グループです。

例えば、書かれた整数が 3, 5, 4 である 3 枚のカードの集合は、整数の集合として \{3, 4, 5\} となり連続する 3 個の整数からなるので連番グループです。一方、書かれた整数が 2, 4, 5 である 3 枚のカードの集合は、24 の間に 3 が欠けているため連番グループではありません。

N 枚のカードすべてを連番グループに分けるとき、グループ数の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • A_i \neq A_j (i \neq j)
  • 入力はすべて整数

入力

N
A_1 A_2 \ldots A_N
  • 1 行目には、カードの枚数を表す整数 N が与えられる。
  • 2 行目には、各カードに書かれた正の整数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。

出力

N 枚のカードすべてを連番グループに分けるときの、グループ数の最小値を 1 行で出力せよ。


入力例 1

3
3 5 4

出力例 1

1

入力例 2

7
2 4 5 10 11 12 7

出力例 2

4

入力例 3

15
100 3 50 51 52 1 2 200 201 202 203 53 4 5 999999999

出力例 3

5

Score : 300 pts

Problem Statement

Takahashi is organizing a card game tournament.

The tournament uses N cards. Card i (1 \leq i \leq N) has a positive integer A_i written on it, and all integers written on the N cards are distinct.

Takahashi wants to divide all N cards into several groups. Each card must belong to exactly one group, and every group must contain at least one card. Furthermore, each group must be a "consecutive group" as defined below.

A set of cards is a consecutive group if the set of integers written on the cards in it can be expressed as \{a, a+1, a+2, \ldots, a+k-1\} for some integer a and positive integer k. In other words, it is a set consisting of k consecutive integers. When k = 1, i.e., a group consisting of just one card, it is also a consecutive group.

For example, a set of 3 cards with the integers 3, 5, 4 written on them forms the integer set \{3, 4, 5\}, which consists of 3 consecutive integers, so it is a consecutive group. On the other hand, a set of 3 cards with the integers 2, 4, 5 is not a consecutive group because 3 is missing between 2 and 4.

When dividing all N cards into consecutive groups, find the minimum number of groups.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • A_i \neq A_j (i \neq j)
  • All inputs are integers

Input

N
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of cards.
  • The second line contains the positive integers A_1, A_2, \ldots, A_N written on each card, separated by spaces.

Output

Print in one line the minimum number of groups when dividing all N cards into consecutive groups.


Sample Input 1

3
3 5 4

Sample Output 1

1

Sample Input 2

7
2 4 5 10 11 12 7

Sample Output 2

4

Sample Input 3

15
100 3 50 51 52 1 2 200 201 202 203 53 4 5 999999999

Sample Output 3

5
D - Conservation Plan for the Botanical Garden

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 366

問題文

高橋君は、ある植物園の管理者です。植物園には N 株の植物があり、それぞれ 1 から N までの番号が付けられています。

各植物 i1 \leq i \leq N)には「観賞価値」A_i と「乾燥耐性」B_i が設定されています。観賞価値が高い植物ほど来園者にとって魅力的であり、乾燥耐性が高い植物ほど水不足に強いです。

今年の夏は猛暑が予想されており、水不足で枯れてしまう植物が出る可能性があります。具体的には、乾燥耐性 B_i が閾値 T 以上の植物は何もしなくても枯れずに残りますが、B_iT 未満の植物は、何も対策をしなければ枯れてしまいます。

高橋君は、枯れてしまう植物を守るため、植物に給水設備を設置することにしました。各植物 i について、給水設備を設置するか設置しないかを選びます。給水設備はどの植物にも設置でき(乾燥耐性が T 以上の植物にも設置できます)、1つも設置しないことも許されます。ただし、各植物に設置できる給水設備は高々 1 つです。植物 i に給水設備を設置するにはコスト C_i がかかり、給水設備を設置された植物は乾燥耐性の値にかかわらず枯れません。

給水設備の設置コストの合計は、高橋君の予算 M を超えてはなりません。

まとめると、植物 i が枯れずに残る条件は、次のいずれか(または両方)を満たすことです:

  • 植物 i に給水設備が設置されている
  • 乾燥耐性 B_iT 以上である

これらの条件をいずれも満たさない植物は枯れてしまいます。なお、両方の条件を同時に満たしても、観賞価値が二重に加算されることはありません。

高橋君は、予算 M 以内で給水設備を設置する植物をうまく選ぶことで、枯れずに残る植物の観賞価値の合計を最大化したいと考えています。

枯れずに残るすべての植物の観賞価値 A_i の総和の最大値を求めてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq M \leq 10^4
  • 1 \leq T \leq 10^9
  • 1 \leq A_i \leq 10^6
  • 1 \leq B_i \leq 10^9
  • 1 \leq C_i \leq 10^4
  • 入力はすべて整数である

入力

N M T
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_N B_N C_N
  • 1 行目には、植物の株数 N 、高橋君の予算 M 、乾燥耐性の閾値 T が、スペース区切りで与えられる。
  • 続く N 行のうち i 行目には、植物 i の観賞価値 A_i 、乾燥耐性 B_i 、給水設備の設置コスト C_i が、スペース区切りで与えられる。

出力

枯れずに残る植物の観賞価値の合計の最大値を 1 行で出力せよ。


入力例 1

3 100 50
80 30 60
50 60 40
30 40 50

出力例 1

130

入力例 2

5 200 100
100 50 80
200 150 120
150 80 90
50 200 30
80 90 70

出力例 2

500

入力例 3

10 500 1000
500 800 100
300 1200 80
450 500 150
200 2000 50
150 900 120
600 600 200
100 1500 40
350 400 180
250 1100 90
400 700 160

出力例 3

2400

Score : 366 pts

Problem Statement

Takahashi is the manager of a botanical garden. The garden contains N plants, each numbered from 1 to N.

Each plant i (1 \leq i \leq N) has an "ornamental value" A_i and a "drought resistance" B_i. Plants with higher ornamental value are more attractive to visitors, and plants with higher drought resistance are more resilient to water shortages.

An intense heatwave is expected this summer, and some plants may wither due to water shortage. Specifically, plants whose drought resistance B_i is at least the threshold T will survive without any intervention, but plants whose B_i is less than T will wither if no measures are taken.

To protect the plants that would wither, Takahashi has decided to install irrigation equipment on some plants. For each plant i, he chooses whether or not to install irrigation equipment. Irrigation equipment can be installed on any plant (including plants whose drought resistance is at least T), and it is also allowed to install none at all. However, at most one irrigation equipment can be installed per plant. Installing irrigation equipment on plant i costs C_i, and a plant with irrigation equipment installed will not wither regardless of its drought resistance value.

The total installation cost of the irrigation equipment must not exceed Takahashi's budget M.

In summary, plant i survives (does not wither) if it satisfies either (or both) of the following conditions:

  • Irrigation equipment is installed on plant i
  • Its drought resistance B_i is at least T

Plants that satisfy neither of these conditions will wither. Note that even if both conditions are satisfied simultaneously, the ornamental value is not counted twice.

Takahashi wants to maximize the total ornamental value of the surviving plants by choosing which plants to install irrigation equipment on, within the budget M.

Find the maximum possible sum of ornamental values A_i over all surviving plants.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq M \leq 10^4
  • 1 \leq T \leq 10^9
  • 1 \leq A_i \leq 10^6
  • 1 \leq B_i \leq 10^9
  • 1 \leq C_i \leq 10^4
  • All input values are integers

Input

N M T
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_N B_N C_N
  • The first line contains the number of plants N, Takahashi's budget M, and the drought resistance threshold T, separated by spaces.
  • The i-th of the following N lines contains the ornamental value A_i, drought resistance B_i, and irrigation equipment installation cost C_i of plant i, separated by spaces.

Output

Output the maximum possible total ornamental value of the surviving plants on a single line.


Sample Input 1

3 100 50
80 30 60
50 60 40
30 40 50

Sample Output 1

130

Sample Input 2

5 200 100
100 50 80
200 150 120
150 80 90
50 200 30
80 90 70

Sample Output 2

500

Sample Input 3

10 500 1000
500 800 100
300 1200 80
450 500 150
200 2000 50
150 900 120
600 600 200
100 1500 40
350 400 180
250 1100 90
400 700 160

Sample Output 3

2400
E - Loading Cargo

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433

問題文

高橋君は引っ越しのために、段ボール箱をトラックの荷台に積み上げようとしています。

高橋君は N 個の段ボール箱を持っており、i 番目の段ボール箱の重さは W_i、耐荷重は D_i です。高橋君はこれらの段ボール箱の中から何個か選び(0 個でもよいが、同じ段ボール箱を複数回選ぶことはできない)、選んだ段ボール箱を好きな順番で下から上へ一列に積み上げます。

ただし、段ボール箱には耐荷重の制限があります。ある段ボール箱の上に載っているすべての段ボール箱の重さの合計が、その段ボール箱の耐荷重を超えてしまう(すなわち、耐荷重より真に大きい)と、その段ボール箱は潰れてしまいます。重さの合計が耐荷重以下であれば潰れません。1 つでも潰れる段ボール箱があると、積み上げは成立しません。

高橋君は積み上げが成立するように段ボール箱を選んで積み上げたいと考えています。積み上げに使用する段ボール箱の個数を最大化してください。

より厳密に述べます。N 個の段ボール箱の中から部分集合 S を選びます(S は空集合でもよい)。S に含まれる段ボール箱を何らかの順番で下から上へ一列に積みます。S に含まれるすべての段ボール箱について、その段ボール箱より上にあるすべての段ボール箱の重さの合計がその段ボール箱の耐荷重以下であるとき、この積み上げは 成立する ものとします。ある S に対して、積み上げが成立するような積み上げ順が少なくとも 1 つ存在するとき、その S実現可能 であるとします。実現可能な S の中で、|S| の最大値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq W_i \leq 10^9
  • 0 \leq D_i \leq 10^9
  • 入力はすべて整数である。

入力

N
W_1 D_1
W_2 D_2
\vdots
W_N D_N
  • 1 行目には、段ボール箱の個数を表す整数 N が与えられる。
  • 2 行目から N + 1 行目では、各段ボール箱の情報が与えられる。
  • 1 + i 行目では、i 番目の段ボール箱の重さ W_i と耐荷重 D_i がスペース区切りで与えられる。

出力

実現可能な S における |S| の最大値、すなわち積み上げが成立するように選べる段ボール箱の個数の最大値を 1 行で出力せよ。


入力例 1

3
3 5
2 3
4 2

出力例 1

2

入力例 2

5
1 100
2 50
3 20
1 10
2 5

出力例 2

5

入力例 3

8
10 90
20 70
30 50
40 30
50 10
100 0
5 1000000000
1000000000 0

出力例 3

5

Score : 433 pts

Problem Statement

Takahashi is trying to stack cardboard boxes onto a truck bed for moving.

Takahashi has N cardboard boxes, where the i-th box has weight W_i and load capacity D_i. He selects some of these boxes (possibly 0, but each box can be selected at most once) and stacks the selected boxes in a single column from bottom to top in any order he likes.

However, there is a load capacity constraint on the boxes. If the total weight of all boxes placed on top of a given box exceeds that box's load capacity (i.e., is strictly greater than the load capacity), that box will be crushed. If the total weight is at most the load capacity, the box will not be crushed. If even one box is crushed, the stacking is not valid.

Takahashi wants to select and stack boxes so that the stacking is valid. Maximize the number of boxes used in the stacking.

More precisely: select a subset S from the N boxes (S may be empty). Stack the boxes in S in some order in a single column from bottom to top. The stacking is said to be valid if, for every box in S, the total weight of all boxes above it is at most that box's load capacity. A subset S is said to be feasible if there exists at least one ordering of the boxes in S such that the stacking is valid. Find the maximum value of |S| among all feasible subsets S.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq W_i \leq 10^9
  • 0 \leq D_i \leq 10^9
  • All input values are integers.

Input

N
W_1 D_1
W_2 D_2
\vdots
W_N D_N
  • The first line contains an integer N, the number of cardboard boxes.
  • The next N lines give the information for each box.
  • The (1 + i)-th line contains the weight W_i and load capacity D_i of the i-th box, separated by a space.

Output

Print on a single line the maximum value of |S| over all feasible subsets S, that is, the maximum number of boxes that can be selected so that the stacking is valid.


Sample Input 1

3
3 5
2 3
4 2

Sample Output 1

2

Sample Input 2

5
1 100
2 50
3 20
1 10
2 5

Sample Output 2

5

Sample Input 3

8
10 90
20 70
30 50
40 30
50 10
100 0
5 1000000000
1000000000 0

Sample Output 3

5