A - TLD

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

英小文字と . のみからなる文字列 S が与えられます。
S. で分割したときの末尾の文字列を出力してください。
すなわち、. を含まない S の接尾辞のうち最長のものを出力してください。

制約

  • S は英小文字と . からなる、長さ 2 以上 100 以下の文字列
  • S には .1 つ以上含まれる
  • S の末尾は . ではない

入力

入力は以下の形式で標準入力から与えられる。

S

出力

答えを出力せよ。


入力例 1

atcoder.jp

出力例 1

jp

atcoder.jp の、 . を含まない最長の接尾辞は jp です。


入力例 2

translate.google.com

出力例 2

com

S. が複数含まれることもあります。


入力例 3

.z

出力例 3

z

S. から始まることもあります。


入力例 4

..........txt

出力例 4

txt

S 中で . が連続することもあります。

Score: 100 points

Problem Statement

You are given a string S consisting of lowercase English letters and the character ..
Print the last substring when S is split by .s.
In other words, print the longest suffix of S that does not contain ..

Constraints

  • S is a string of length between 2 and 100, inclusive, consisting of lowercase English letters and ..
  • S contains at least one ..
  • S does not end with ..

Input

The input is given from Standard Input in the following format:

S

Output

Print the answer.


Sample Input 1

atcoder.jp

Sample Output 1

jp

The longest suffix of atcoder.jp that does not contain . is jp.


Sample Input 2

translate.google.com

Sample Output 2

com

S may contain multiple .s.


Sample Input 3

.z

Sample Output 3

z

S may start with ..


Sample Input 4

..........txt

Sample Output 4

txt

S may contain consecutive .s.

B - Too Many Requests

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

正整数 N,M が与えられます。
N 行出力してください。
i 行目 (1\leq i\leq N) には、i\leq M のとき OK を、 そうでないとき、Too Many Requests を出力してください。

制約

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • N,M は整数

入力

入力は以下の形式で標準入力から与えられる。

N M

出力

問題文の指示に従って、N 行出力せよ。


入力例 1

5 3

出力例 1

OK
OK
OK
Too Many Requests
Too Many Requests

N=5, M=3 のため、
1,2,3 行目には OK を、
4,5 行目には Too Many Requests を出力します。


入力例 2

3 5

出力例 2

OK
OK
OK

N=3, M=5 のため、 1,2,3 行目に OK を出力します。

Score : 100 points

Problem Statement

You are given positive integers N and M.
Print N lines.
The i-th line (1\leq i\leq N) should contain OK if i\leq M, and Too Many Requests otherwise.

Constraints

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • N and M are integers.

Input

The input is given from Standard Input in the following format:

N M

Output

Print N lines according to the instructions in the problem statement.


Sample Input 1

5 3

Sample Output 1

OK
OK
OK
Too Many Requests
Too Many Requests

Since N=5 and M=3,
print OK on the 1st, 2nd, and 3rd lines,
and print Too Many Requests on the 4th and 5th lines.


Sample Input 2

3 5

Sample Output 2

OK
OK
OK

Since N=3 and M=5, print OK on the 1st, 2nd, and 3rd lines.

C - AtCoder Amusement Park

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

AtCoder 遊園地には K 人乗りのアトラクションがあります。 現在、このアトラクションの待機列には N グループが並んでいます。

先頭から i 番目 (1\leq i\leq N) のグループは A _ i 人組です。 すべての i (1\leq i\leq N) について、A _ i\leq K です。

高橋君はこのアトラクションのスタッフとして、並んでいるグループを次の手順に従って誘導します。

はじめ、アトラクションには誰も誘導されておらず、空席は K 個あります。

  1. 待機列に並んでいるグループがない場合、アトラクションをスタートさせ、誘導を終了する。
  2. アトラクションの空席の数と待機列の先頭に並んでいるグループの人数を比較し、次のどちらかを行う。
    • 待機列の先頭に並んでいるグループの人数よりアトラクションの空席の数のほうが少ない場合、アトラクションをスタートさせる。 スタートしたのち、アトラクションの空席が K 個になる。
    • そうでない場合、待機列の先頭に並んでいるグループを全員アトラクションへ誘導する。 先頭のグループが待機列から取り出され、アトラクションの空席がグループの人数ぶんだけ減少する。
  3. 1 に戻る。

ただし、誘導を開始したあとに追加でグループが並ぶことはないとします。 以上の条件のもとで、この手順が有限回で終了することが示せます。

高橋君が誘導を開始してから誘導を終了するまで、何回アトラクションをスタートさせるか求めてください。

制約

  • 1\leq N\leq100
  • 1\leq K\leq100
  • 1\leq A _ i\leq K\ (1\leq i\leq N)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N K
A _ 1 A _ 2 \ldots A _ N

出力

答えを出力せよ。


入力例 1

7 6
2 5 1 4 1 2 3

出力例 1

4

はじめ、7 つのグループは以下のように並んでいます。

高橋君の誘導の様子の一部を以下の図に示します。

  • はじめ、先頭に並んでいるグループは 2 人のグループで、空席は 6 個です。よって、高橋君は先頭のグループをアトラクションに誘導し、空席は 4 個になります。
  • 次に、先頭に並んでいるグループは 5 人のグループで、空席の個数 4 より多いため、アトラクションをスタートさせます。
  • 空席が 6 個になったため、先頭のグループをアトラクションに誘導し、空席は 1 個になります。
  • 次に先頭に並んでいるのは 1 人なので、アトラクションに誘導し、空席は 0 個になります。

すべての誘導が終了するまでに、高橋君は 4 回アトラクションをスタートさせることになります。 よって、4 を出力してください。


入力例 2

7 10
1 10 1 10 1 10 1

出力例 2

7

入力例 3

15 100
73 8 55 26 97 48 37 47 35 55 5 17 62 2 60

出力例 3

8

Score: 200 points

Problem Statement

The AtCoder amusement park has an attraction that can accommodate K people. Now, there are N groups lined up in the queue for this attraction.

The i-th group from the front (1\leq i\leq N) consists of A_i people. For all i (1\leq i\leq N), it holds that A_i \leq K.

Takahashi, as a staff member of this attraction, will guide the groups in the queue according to the following procedure.

Initially, no one has been guided to the attraction, and there are K empty seats.

  1. If there are no groups in the queue, start the attraction and end the guidance.
  2. Compare the number of empty seats in the attraction with the number of people in the group at the front of the queue, and do one of the following:
    • If the number of empty seats is less than the number of people in the group at the front, start the attraction. Then, the number of empty seats becomes K again.
    • Otherwise, guide the entire group at the front of the queue to the attraction. The front group is removed from the queue, and the number of empty seats decreases by the number of people in the group.
  3. Go back to step 1.

Here, no additional groups will line up after the guidance has started. Under these conditions, it can be shown that this procedure will end in a finite number of steps.

Determine how many times the attraction will be started throughout the guidance.

Constraints

  • 1\leq N\leq 100
  • 1\leq K\leq 100
  • 1\leq A_i\leq K\ (1\leq i\leq N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

7 6
2 5 1 4 1 2 3

Sample Output 1

4

Initially, the seven groups are lined up as follows:

Part of Takahashi's guidance is shown in the following figure:

  • Initially, the group at the front has 2 people, and there are 6 empty seats. Thus, he guides the front group to the attraction, leaving 4 empty seats.
  • Next, the group at the front has 5 people, which is more than the 4 empty seats, so the attraction is started.
  • After the attraction is started, there are 6 empty seats again, so the front group is guided to the attraction, leaving 1 empty seat.
  • Next, the group at the front has 1 person, so they are guided to the attraction, leaving 0 empty seats.

In total, he starts the attraction four times before the guidance is completed. Therefore, print 4.


Sample Input 2

7 10
1 10 1 10 1 10 1

Sample Output 2

7

Sample Input 3

15 100
73 8 55 26 97 48 37 47 35 55 5 17 62 2 60

Sample Output 3

8
D - Second Best

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

長さ N の整数列 A=(A_1,\ldots,A_N) が与えられます。ここで A_1,A_2,\ldots,A_N は相異なります。

A の中で二番目に大きい要素は A の何番目の要素でしょうか。

制約

  • 2\leq N\leq 100
  • 1\leq A_i \leq 10^9
  • A_1,A_2,\ldots,A_N は相異なる
  • 入力される数値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N 
A_1 A_2 \ldots A_{N}

出力

A の中で二番目に大きい要素が AX 番目であるとき、X を整数として出力せよ。


入力例 1

4
8 2 5 1

出力例 1

3

A の中で二番目に大きい要素は A_3 なので 3 を出力してください。


入力例 2

8
1 2 3 4 5 10 9 11

出力例 2

6

Score : 200 points

Problem Statement

You are given an integer sequence A=(A_1,\ldots,A_N) of length N. Here, A_1, A_2, \ldots, A_N are all distinct.

Which element in A is the second largest?

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 10^9
  • A_1, A_2, \ldots, A_N are all distinct.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N 
A_1 A_2 \ldots A_{N}

Output

Print the integer X such that the X-th element in A is the second largest.


Sample Input 1

4
8 2 5 1

Sample Output 1

3

The second largest element in A is A_3, so print 3.


Sample Input 2

8
1 2 3 4 5 10 9 11

Sample Output 2

6
E - Remembering the Days

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

ある地方に、1 から N の番号がついた N 個の街と、1 から M の番号がついた M 本の道路があります。

i 番目の道路は街 A_i と街 B_i を双方向に結び、長さは C_i です。

好きな街からスタートして同じ街を二度以上通らずに別の街へ移動するときの、通る道路の長さの和としてありえる最大値を求めてください。

制約

  • 2 \leq N \leq 10
  • 1 \leq M \leq \frac{N(N-1)}{2}
  • 1\leq A_i < B_i \leq N
  • (A_i,B_i) は相異なる
  • 1\leq C_i \leq 10^8
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

N M
A_1 B_1 C_1
\vdots
A_M B_M C_M

出力

答えを出力せよ。


入力例 1

4 4
1 2 1
2 3 10
1 3 100
1 4 1000

出力例 1

1110

4\to 1\to 3\to 2 と移動すると、通る道路の長さの和は 1110 となります。


入力例 2

10 1
5 9 1

出力例 2

1

道路と繋がっていない街が存在するかもしれません。


入力例 3

10 13
1 2 1
1 10 1
2 3 1
3 4 4
4 7 2
4 8 1
5 8 1
5 9 3
6 8 1
6 9 5
7 8 1
7 9 4
9 10 3

出力例 3

20

図

Score : 300 points

Problem Statement

A region has N towns numbered 1 to N, and M roads numbered 1 to M.

The i-th road connects town A_i and town B_i bidirectionally with length C_i.

Find the maximum possible total length of the roads you traverse when starting from a town of your choice and getting to another town without passing through the same town more than once.

Constraints

  • 2 \leq N \leq 10
  • 1 \leq M \leq \frac{N(N-1)}{2}
  • 1 \leq A_i < B_i \leq N
  • The pairs (A_i,B_i) are distinct.
  • 1\leq C_i \leq 10^8
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N M
A_1 B_1 C_1
\vdots
A_M B_M C_M

Output

Print the answer.


Sample Input 1

4 4
1 2 1
2 3 10
1 3 100
1 4 1000

Sample Output 1

1110

If you travel as 4\to 1\to 3\to 2, the total length of the roads you traverse is 1110.


Sample Input 2

10 1
5 9 1

Sample Output 2

1

There may be a town that is not connected to a road.


Sample Input 3

10 13
1 2 1
1 10 1
2 3 1
3 4 4
4 7 2
4 8 1
5 8 1
5 9 3
6 8 1
6 9 5
7 8 1
7 9 4
9 10 3

Sample Output 3

20

Figure