A - Tomorrow

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

AtCoder 国の暦では、1 年は 1 月から M 月までの M ヶ月からなり、どの月も 1 日から D 日までの D 日からなります。

AtCoder 国の暦で y 年 m 月 d 日の翌日は何年何月何日であるか求めてください。

制約

  • 1000 \leq y \leq 9000
  • 1 \leq m \leq M \leq 99
  • 1 \leq d \leq D \leq 99
  • 入力は全て整数である

入力

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

M D
y m d

出力

AtCoder 国の暦で y 年 m 月 d 日の翌日が y' 年 m' 月 d' 日であるとき、y',m',d' をこの順に空白区切りで出力せよ。


入力例 1

12 30
2023 12 30

出力例 1

2024 1 1

AtCoder 国の暦では 1 年は 12 ヶ月であり、どの月も 30 日からなります。 よって、2023 年 12 月 30 日の翌日は 2024 年 1 月 1 日になります。


入力例 2

36 72
6789 23 45

出力例 2

6789 23 46

AtCoder 国の暦では 1 年は 36 ヶ月であり、どの月も 72 日からなります。 よって、6789 年 23 月 45 日の翌日は 6789 年 23 月 46 日になります。


入力例 3

12 30
2012 6 20

出力例 3

2012 6 21

Score : 100 points

Problem Statement

In the calendar of AtCoder Kingdom, a year consists of M months from month 1 to month M, and each month consists of D days from day 1 to day D.

What day follows year y, month m, day d in this calendar?

Constraints

  • 1000 \leq y \leq 9000
  • 1 \leq m \leq M \leq 99
  • 1 \leq d \leq D \leq 99
  • All input values are integers.

Input

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

M D
y m d

Output

If the day following year y, month m, day d in the calendar of AtCoder Kingdom is year y', month m', day d', print y', m', and d' in this order, separated by spaces.


Sample Input 1

12 30
2023 12 30

Sample Output 1

2024 1 1

In the calendar of the kingdom, a year consists of 12 months, and each month consists of 30 days. Thus, the day following year 2023, month 12, day 30 is year 2024, month 1, day 1.


Sample Input 2

36 72
6789 23 45

Sample Output 2

6789 23 46

In the calendar of the kingdom, one year consists of 36 months, and each month consists of 72 days. Thus, the day following year 6789, month 23, day 45 is year 6789, month 23, day 46.


Sample Input 3

12 30
2012 6 20

Sample Output 3

2012 6 21
B - Shout Everyday

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 150 点

問題文

AtCoder 王国の住民は A 時になるとたこ焼きへの愛を叫ぶことになっています。

AtCoder 王国に住む高橋君は毎日 B 時に就寝し C 時に起床します。高橋君は、起きているときはたこ焼きへの愛を叫ぶことができ、寝ているときは叫ぶことができません。高橋君が毎日たこ焼きへの愛を叫ぶことができているか判定してください。ただし、一日は 24 時間であり、高橋君が寝ている時間は 24 時間未満であるとします。

制約

  • 0\leq A,B,C\lt 24
  • A,B,C は相異なる
  • 入力は全て整数

入力

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

A B C

出力

高橋君が毎日たこ焼きへの愛を叫ぶことができているならば Yes を、そうでないならば No を出力せよ。


入力例 1

21 8 14

出力例 1

Yes

高橋君は毎日 8 時に就寝し 14 時に起床します。21 時には起きているため、高橋君は毎日たこ焼きへの愛を叫ぶことができます。よって Yes を出力します。


入力例 2

0 21 7

出力例 2

No

高橋君は毎日 21 時に就寝し 7 時に起床します。0 時には起きていないため、高橋君は毎日たこ焼きへの愛を叫ぶことができません。よって No を出力します。


入力例 3

10 7 17

出力例 3

No

Score : 150 points

Problem Statement

In the Kingdom of AtCoder, residents are required to shout their love for takoyaki at A o'clock every day.

Takahashi, who lives in the Kingdom of AtCoder, goes to bed at B o'clock and wakes up at C o'clock every day (in the 24-hour clock). He can shout his love for takoyaki when he is awake, but cannot when he is asleep. Determine whether he can shout his love for takoyaki every day. Here, a day has 24 hours, and his sleeping time is less than 24 hours.

Constraints

  • 0\leq A,B,C\lt 24
  • A, B, and C are pairwise different.
  • All input values are integers.

Input

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

A B C

Output

Print Yes if Takahashi can shout his love for takoyaki every day, and No otherwise.


Sample Input 1

21 8 14

Sample Output 1

Yes

Takahashi goes to bed at 8 o'clock and wakes up at 14 o'clock every day. He is awake at 21 o'clock, so he can shout his love for takoyaki every day. Therefore, print Yes.


Sample Input 2

0 21 7

Sample Output 2

No

Takahashi goes to bed at 21 o'clock and wakes up at 7 o'clock every day. He is not awake at 0 o'clock, so he cannot shout his love for takoyaki every day. Therefore, print No.


Sample Input 3

10 7 17

Sample Output 3

No
C - 459

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

英小文字のみからなる N 個の文字列 S_1,S_2,\ldots,S_N が与えられます。

N 個の数字 C_1,C_2,\ldots,C_N を以下のように定義します。

  • S_i の先頭の文字が a, b, c のいずれかならば C_i=2
  • S_i の先頭の文字が d, e, f のいずれかならば C_i=3
  • S_i の先頭の文字が g, h, i のいずれかならば C_i=4
  • S_i の先頭の文字が j, k, l のいずれかならば C_i=5
  • S_i の先頭の文字が m, n, o のいずれかならば C_i=6
  • S_i の先頭の文字が p, q, r, s のいずれかならば C_i=7
  • S_i の先頭の文字が t, u, v のいずれかならば C_i=8
  • S_i の先頭の文字が w, x, y, z のいずれかならば C_i=9

C_1,C_2,\ldots,C_N をこの順に連結した文字列を出力してください。

制約

  • 1\leq N\leq 10
  • N は整数
  • S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列

入力

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

N
S_1 S_2 \ldots S_N

出力

C_1,C_2,\ldots,C_N をこの順に連結した文字列を出力せよ。


入力例 1

2
algorithm heuristic

出力例 1

24
  • S_1=algorithm の先頭の文字は a であるため、C_1=2 となります。
  • S_2=heuristic の先頭の文字は h であるため、C_2=4 となります。

よって、これらを連結した 24 を出力します。


入力例 2

3
i love you

出力例 2

459

Score : 200 points

Problem Statement

You are given N strings S_1, S_2, \ldots, S_N consisting of lowercase English letters.

Define N digits C_1, C_2, \ldots, C_N as follows:

  • If the first character of S_i is one of a, b, c, then C_i= 2
  • If the first character of S_i is one of d, e, f, then C_i= 3
  • If the first character of S_i is one of g, h, i, then C_i= 4
  • If the first character of S_i is one of j, k, l, then C_i= 5
  • If the first character of S_i is one of m, n, o, then C_i= 6
  • If the first character of S_i is one of p, q, r, s, then C_i= 7
  • If the first character of S_i is one of t, u, v, then C_i= 8
  • If the first character of S_i is one of w, x, y, z, then C_i= 9

Output the string obtained by concatenating C_1, C_2, \ldots, C_N in this order.

Constraints

  • 1 \leq N \leq 10
  • N is an integer.
  • S_i is a string of length between 1 and 10, inclusive, consisting of lowercase English letters.

Input

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

N
S_1 S_2 \ldots S_N

Output

Output the string obtained by concatenating C_1, C_2, \ldots, C_N in this order.


Sample Input 1

2
algorithm heuristic

Sample Output 1

24
  • The first character of S_1= algorithm is a, so C_1= 2.
  • The first character of S_2= heuristic is h, so C_2= 4.

Thus, output 24, which is their concatenation.


Sample Input 2

3
i love you

Sample Output 2

459
D - Inverse Prefix Sum

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

整数 N と長さ N の数列 S=(S_1,\ldots,S_N) が与えられます。

長さ N の数列 A=(A_1,\ldots,A_N) であって、k=1,\ldots,N の全てについて以下の条件を満たすものを求めてください。

  • A_1+A_2+\ldots+A_k = S_k

なお、このような数列 A は必ず存在し、一意に定まります。

制約

  • 1 \leq N \leq 10
  • -10^9\leq S_i \leq 10^9
  • 入力は全て整数である

入力

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

N
S_1 \ldots S_N

出力

全ての条件を満たす数列 A=(A_1,\ldots,A_N) の各要素を、順に空白区切りで出力せよ。


入力例 1

3
3 4 8

出力例 1

3 1 4
  • A_1=3=S_1
  • A_1+A_2=3+1=4=S_2
  • A_1+A_2+A_3=3+1+4=8=S_3

であり、たしかに全ての条件を満たしています。


入力例 2

10
314159265 358979323 846264338 -327950288 419716939 -937510582 97494459 230781640 628620899 -862803482

出力例 2

314159265 44820058 487285015 -1174214626 747667227 -1357227521 1035005041 133287181 397839259 -1491424381

Score : 200 points

Problem Statement

You are given an integer N and a sequence S=(S_1,\ldots,S_N) of length N.

Find a sequence A=(A_1,\ldots,A_N) of length N that satisfies the following condition for all k=1,\ldots,N:

  • A_1+A_2+\ldots+A_k = S_k.

Such a sequence A always exists and is unique.

Constraints

  • 1 \leq N \leq 10
  • -10^9\leq S_i \leq 10^9
  • All values in the input are integers.

Input

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

N
S_1 \ldots S_N

Output

Print the elements of a sequence A=(A_1,\ldots,A_N) that satisfies all the conditions in order, separated by spaces.


Sample Input 1

3
3 4 8

Sample Output 1

3 1 4

The sequence in the output actually satisfies all the conditions:

  • A_1=3=S_1;
  • A_1+A_2=3+1=4=S_2;
  • A_1+A_2+A_3=3+1+4=8=S_3.

Sample Input 2

10
314159265 358979323 846264338 -327950288 419716939 -937510582 97494459 230781640 628620899 -862803482

Sample Output 2

314159265 44820058 487285015 -1174214626 747667227 -1357227521 1035005041 133287181 397839259 -1491424381
E - Kaiten Sushi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350 点

問題文

とある回転寿司に、1 から N までの番号が付けられた N 人の人が訪れています。 人 i の 美食度 は A_i です。

今からベルトコンベア上を M 個の寿司が流れます。 j 番目に流れる寿司の 美味しさ は B_j です。 それぞれの寿司は、人 1,2,\dots,N の前をこの順に流れていきます。 それぞれの人は、美味しさが自分の美食度以上である寿司が自分の前に流れてきたときはその寿司を取って食べ、それ以外のときは何もしません。 人 i が取って食べた寿司は、人 j\ (j > i) の前にはもう流れてきません。

M 個の寿司それぞれについて、その寿司を誰が食べるか、あるいは誰も食べないかどうかを求めてください。

制約

  • 1\leq N,M \leq 2\times 10^5
  • 1\leq A_i,B_i \leq 2\times 10^5
  • 入力は全て整数

入力

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

N M
A_1 A_2 \dots A_N
B_1 B_2 \dots B_M

出力

M 行出力せよ。 j\ (1\leq j \leq M) 行目には、j 番目に流れる寿司を食べる人がいるならばその人の番号を、そうでないならば -1 を出力せよ。


入力例 1

3 3
3 8 2
5 2 1

出力例 1

1
3
-1
  • 1 番目の寿司について、
    • まず人 1 の前を流れます。B_1 \geq A_1 なので、人 1 はこれを取って食べます。
    • 人 2,3 の前にはこの寿司は流れてきません。
  • 2 番目の寿司について、
    • まず人 1 の前を流れます。B_2 < A_1 なので、人 1 は何もしません。
    • 次に人 2 の前を流れます。B_2 < A_2 なので、人 2 は何もしません。
    • 最後に人 3 の前を流れます。B_2 \geq A_3 なので、人 3 はこれを取って食べます。
  • 3 番目の寿司について、
    • まず人 1 の前を流れます。B_3 < A_1 なので、人 1 は何もしません。
    • 次に人 2 の前を流れます。B_3 < A_2 なので、人 2 は何もしません。
    • 最後に人 3 の前を流れます。B_3 < A_3 なので、人 3 は何もしません。
    • よって、誰もこの寿司を食べません。

入力例 2

3 3
1 1 1
1 1 1

出力例 2

1
1
1

入力例 3

10 5
60 83 76 45 70 91 37 58 94 22
70 39 52 33 18

出力例 3

1
7
4
10
-1

Score: 350 points

Problem Statement

There are N people numbered from 1 to N visiting a conveyor belt sushi restaurant. The gourmet level of person i is A_i.

Now, M pieces of sushi will be placed on the conveyor belt. The deliciousness of the j-th sushi is B_j. Each piece of sushi passes in front of people 1, 2, \dots, N in this order. Each person, when a sushi whose deliciousness is not less than their gourmet level passes in front of them, will take and eat that sushi; otherwise, they do nothing. A sushi that person i takes and eats will no longer pass in front of person j\ (j > i).

For each of the M pieces of sushi, determine who eats that sushi, or if nobody eats it.

Constraints

  • 1 \leq N, M \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq 2 \times 10^5
  • All input values are integers.

Input

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

N M
A_1 A_2 \dots A_N
B_1 B_2 \dots B_M

Output

Print M lines. The j-th line (1 \leq j \leq M) should contain the number representing the person who eats the j-th sushi, or -1 if nobody eats it.


Sample Input 1

3 3
3 8 2
5 2 1

Sample Output 1

1
3
-1
  • For the 1st sushi:
    • It first passes in front of person 1. Since B_1 \geq A_1, person 1 takes and eats it.
    • It will not pass in front of person 2 and 3.
  • For the 2nd sushi:
    • It first passes in front of person 1. Since B_2 < A_1, person 1 does nothing.
    • Next, it passes in front of person 2. Since B_2 < A_2, person 2 does nothing.
    • Finally, it passes in front of person 3. Since B_2 \geq A_3, person 3 takes and eats it.
  • For the 3rd sushi:
    • It first passes in front of person 1. Since B_3 < A_1, person 1 does nothing.
    • Next, it passes in front of person 2. Since B_3 < A_2, person 2 does nothing.
    • Finally, it passes in front of person 3. Since B_3 < A_3, person 3 does nothing.
    • Therefore, nobody eats this sushi.

Sample Input 2

3 3
1 1 1
1 1 1

Sample Output 2

1
1
1

Sample Input 3

10 5
60 83 76 45 70 91 37 58 94 22
70 39 52 33 18

Sample Output 3

1
7
4
10
-1