A - HonestOrDishonest

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 100

問題文

シカのAtCoDeerくんとTopCoDeerくんが「正直者か嘘つきか」ゲームをしています。 このゲームでは、正直者は常にほんとうのことを言い、嘘つきは常に嘘を言います。 文字 ab が入力として与えられます。これらはそれぞれ HD のどちらかです。

a=H のとき、AtCoDeerくんは正直者です。 a=D のとき、AtCoDeerくんは嘘つきです。 b=H のとき、AtCoDeerくんは「TopCoDeerくんは正直者だ」と発言しています。 b=D のとき、AtCoDeerくんは「TopCoDeerくんは嘘つきだ」と発言しています。

これらから判断して、TopCoDeerくんが正直者かどうか判定してください。

制約

  • a=H または D
  • b=H または D

入力

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

a b

出力

TopCoDeerくんが正直者なら H を、嘘つきなら D を出力せよ。


入力例 1

H H

出力例 1

H

AtCoDeerくんは正直者なので、AtCoDeerくんの言っているとおりTopCoDeerくんは正直者です。


入力例 2

D H

出力例 2

D

今度はAtCoDeerくんは嘘つきなので、AtCoDeerくんの言っていることとは異なりTopCoDeerくんは嘘つきです。


入力例 3

D D

出力例 3

H

Score : 100 points

Problem Statement

Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either H or D, and carries the following information:

If a=H, AtCoDeer is honest; if a=D, AtCoDeer is dishonest. If b=H, AtCoDeer is saying that TopCoDeer is honest; if b=D, AtCoDeer is saying that TopCoDeer is dishonest.

Given this information, determine whether TopCoDeer is honest.

Constraints

  • a=H or a=D.
  • b=H or b=D.

Input

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

a b

Output

If TopCoDeer is honest, print H. If he is dishonest, print D.


Sample Input 1

H H

Sample Output 1

H

In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.


Sample Input 2

D H

Sample Output 2

D

In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.


Sample Input 3

D D

Sample Output 3

H
B - NarrowRectanglesEasy

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

シカのAtCoDeerくんは縦の長さ 1、横の長さ W の形をした長方形が二つ机に置いてあるのを見つけました。 机を二次元平面とみなすと、以下の図のように、一つ目の長方形は 縦は [0,1] の範囲を、横は [a,a+W] の範囲を占めており、二つ目の長方形は縦は [1,2] の範囲を、横は [b,b+W] の範囲を占めています。

AtCoDeerくんは二つ目の長方形を横に動かすことで、一つ目の長方形と連結にしようと考えました。 長方形を横に動かさないといけない距離の最小値を求めてください。

制約

  • 入力は全て整数である。
  • 1≦W≦10^5
  • 1≦a,b≦10^5

入力

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

W a b

出力

横に動かす必要のある距離の最小値を出力せよ。


入力例 1

3 2 6

出力例 1

1

問題文中の図のようになっています。この場合左に 1 動かすのが最小です。


入力例 2

3 1 3

出力例 2

0

はじめから連結になっているため、動かす必要はありません。


入力例 3

5 10 1

出力例 3

4

Score : 200 points

Problem Statement

AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:

AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.

Constraints

  • All input values are integers.
  • 1≤W≤10^5
  • 1≤a,b≤10^5

Input

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

W a b

Output

Print the minimum distance the second rectangle needs to be moved.


Sample Input 1

3 2 6

Sample Output 1

1

This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.


Sample Input 2

3 1 3

Sample Output 2

0

The rectangles are already connected, and thus no move is needed.


Sample Input 3

5 10 1

Sample Output 3

4
C - Go Home

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

無限に左右に伸びている数直線上の 0 の地点に時刻 0 にカンガルーがいます。 カンガルーは時刻 i-1 から i にかけて、なにもしないか、もしくは長さがちょうど i のジャンプを、左右どちらかの方向を選んで行えます。 つまり、時刻 i-1 に座標 x にいたとすると、時刻 i には x-i, x, x+i のどれかに存在することが出来ます。 カンガルーの家は座標 X にあります。カンガルーはできるだけ早く座標 X まで移動しようとしています。 カンガルーが座標 X に到着する時刻の最小値を求めてください。

制約

  • X は整数
  • 1≦X≦10^9

入力

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

X

出力

カンガルーが座標 X に到着する時刻の最小値を出力せよ。


入力例 1

6

出力例 1

3

3 回右にジャンプすると時刻 3 に家にたどり着けて、これが最小です。


入力例 2

2

出力例 2

2

時刻 0 にはなにもせず、時刻 1 に右にジャンプすることで時刻 2 に家にたどり着けます。


入力例 3

11

出力例 3

5

Score : 200 points

Problem Statement

There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.

Constraints

  • X is an integer.
  • 1≤X≤10^9

Input

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

X

Output

Print the earliest possible time for the kangaroo to reach coordinate X.


Sample Input 1

6

Sample Output 1

3

The kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time.


Sample Input 2

2

Sample Output 2

2

He can reach his nest at time 2 by staying at his position during the first second, and jumping to the right at the next second.


Sample Input 3

11

Sample Output 3

5
D - No Need

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 600

問題文

シカのAtCoDeerくんは正整数が書かれたカードを N 枚持っています。i(1≦i≦N) 枚目に書かれている数は a_i です。 AtCoDeerくんは大きい数が好きなので、カードに書かれた数の総和が K 以上になるようなカードの部分集合をよい集合と呼びます。

そして、各カード i に対して、そのカードが不必要かどうかを次のように判定します。

  • 「カード i を含む任意のよい集合に対して、その集合からカード i を除いたものもよい集合」 ならカード i不必要
  • それ以外の場合は、不必要でない

不必要なカードの枚数を求めてください。ただし、それぞれの判定は独立に行われ、不必要だからと言ってカードが途中で捨てられたりすることはありません。

制約

  • 入力は全て整数
  • 1≦N≦5000
  • 1≦K≦5000
  • 1≦a_i≦10^9 (1≦i≦N)

部分点

  • N,K≦400 を満たすデータセットに正解した場合は、部分点として 300 点が与えられる。

入力

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

N K
a_1 a_2 ... a_N

出力

不必要なカードの枚数を出力せよ。


入力例 1

3 6
1 4 3

出力例 1

1

よい集合は {2,3} と {1,2,3} の二つです。

カード 1 を含むよい集合は {1,2,3} しかなく、これから 1 を取り除いた {2,3} もよい集合なので、カード 1 は不必要です。

また、よい集合である {2,3} から 2 を取り除いた集合 {3} はよい集合ではないため、カード 2 は不必要ではありません。

カード 3 も同様に不必要ではないため、答えは 1 です。


入力例 2

5 400
3 1 4 1 5

出力例 2

5

この場合よい集合は存在しないため、全てのカードは不必要となります。


入力例 3

6 20
10 4 3 10 25 2

出力例 3

3

Score : 600 points

Problem Statement

AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.

Then, for each card i, he judges whether it is unnecessary or not, as follows:

  • If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
  • Otherwise, card i is NOT unnecessary.

Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.

Constraints

  • All input values are integers.
  • 1≤N≤5000
  • 1≤K≤5000
  • 1≤a_i≤10^9 (1≤i≤N)

Partial Score

  • 300 points will be awarded for passing the test set satisfying N,K≤400.

Input

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

N K
a_1 a_2 ... a_N

Output

Print the number of the unnecessary cards.


Sample Input 1

3 6
1 4 3

Sample Output 1

1

There are two good sets: {2,3} and {1,2,3}.

Card 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is also good. Thus, card 1 is unnecessary.

For card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is NOT unnecessary.

Neither is card 3 for a similar reason, hence the answer is 1.


Sample Input 2

5 400
3 1 4 1 5

Sample Output 2

5

In this case, there is no good set. Therefore, all the cards are unnecessary.


Sample Input 3

6 20
10 4 3 10 25 2

Sample Output 3

3