E - Sum of Numbers Greater Than Me

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。

i=1,\ldots,N のそれぞれについて次の問題を解いてください。

問題:A の要素のうち A_i より大きな要素全ての和を求めよ。

制約

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 10^6
  • 入力は全て整数である

入力

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

N
A_1 \ldots A_N

出力

1\leq k\leq N について、i=k に対する問題の答えを B_k とする。B_1,\ldots,B_N をこの順に空白区切りで出力せよ。


入力例 1

5
1 4 1 4 2

出力例 1

10 0 10 0 8
  • i=1 のとき A_1=1 より大きな要素の和は 4+4+2=10
  • i=2 のとき A_2=4 より大きな要素の和は 0
  • i=3 のとき A_3=1 より大きな要素の和は 4+4+2=10
  • i=4 のとき A_4=4 より大きな要素の和は 0
  • i=5 のとき A_5=2 より大きな要素の和は 4+4=8

入力例 2

10
31 42 59 26 53 58 97 93 23 54

出力例 2

456 414 190 487 361 249 0 97 513 307

入力例 3

50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

出力例 3

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Score : 300 points

Problem Statement

You are given a sequence A=(A_1,\ldots,A_N) of length N.

For each i=1,\ldots,N, solve the following problem.

Problem: Find the sum of all elements in A that are greater than A_i.

Constraints

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

Input

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

N
A_1 \ldots A_N

Output

For each 1\leq k\leq N, let B_k be the answer to the problem when i=k. Print B_1,\ldots,B_N in this order, separated by spaces.


Sample Input 1

5
1 4 1 4 2

Sample Output 1

10 0 10 0 8
  • For i=1, the sum of elements greater than A_1=1 is 4+4+2=10.
  • For i=2, the sum of elements greater than A_2=4 is 0.
  • For i=3, the sum of elements greater than A_3=1 is 4+4+2=10.
  • For i=4, the sum of elements greater than A_4=4 is 0.
  • For i=5, the sum of elements greater than A_5=2 is 4+4=8.

Sample Input 2

10
31 42 59 26 53 58 97 93 23 54

Sample Output 2

456 414 190 487 361 249 0 97 513 307

Sample Input 3

50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Sample Output 3

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
F - Max Even

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

長さ N の非負整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。

A の異なる 2 要素の和として表せる値の中に偶数が存在するか判定し、存在する場合その最大値を求めてください。

制約

  • 2\leq N \leq 2\times 10^5
  • 0\leq A_i\leq 10^9
  • A の要素は相異なる
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

A の異なる 2 要素の和として表せる値の中に偶数が存在しない場合、-1 を出力せよ。

偶数が存在する場合、その最大値を出力せよ。


入力例 1

3
2 3 4

出力例 1

6

A の異なる 2 要素の和として表せる値は 5,6,7 です。この中に偶数は存在し、その最大値は 6 です。


入力例 2

2
1 0

出力例 2

-1

A の異なる 2 要素の和として表せる値は 1 です。この中に偶数は存在しないので、 -1 を出力してください。

Score : 300 points

Problem Statement

You are given a sequence A=(A_1,A_2,\ldots,A_N) of length N consisting of non-negative integers.

Determine if there is an even number represented as the sum of two different elements of A. If it exists, find the maximum such number.

Constraints

  • 2\leq N \leq 2\times 10^5
  • 0\leq A_i\leq 10^9
  • The elements of A are distinct.
  • All values in the input are integers.

Input

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

N
A_1 A_2 \ldots A_N

Output

Print -1 if there is no even number represented as the sum of two different elements of A.

If such an even number exists, print the maximum such number.


Sample Input 1

3
2 3 4

Sample Output 1

6

The values represented as the sum of two distinct elements of A are 5, 6, and 7. We have an even number here, and the maximum is 6.


Sample Input 2

2
1 0

Sample Output 2

-1

The value represented as the sum of two distinct elements of A is 1. We have no even number here, so -1 should be printed.

G - Project Planning

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

キーエンスには N 個の部署があり、i\,(1 \leq i \leq N) 番目の部署には A_i 人の社員が所属しています。異なる部署に同じ社員が所属していることはありません。

キーエンスは、部署をまたいだ全社横断プロジェクトを計画しています。1 つのプロジェクトは K 個の相異なる部署から 1 人ずつ選出して作り、ちょうど K 人から構成されるようにします。

プロジェクトは最大でいくつ作れますか?ただし、1 人が複数のプロジェクトに参加することはできません。

制約

  • 1 \leq K \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^{12}
  • 入力は全て整数

入力

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

N K
A_1 A_2 \ldots A_N

出力

プロジェクトの個数の最大値を出力せよ。


入力例 1

3 3
2 3 4

出力例 1

2

3 個の部署それぞれから 1 人ずつ選出したプロジェクトを 2 つ作ることができます。


入力例 2

4 2
1 1 3 4

出力例 2

4

入力例 3

4 3
1 1 3 4

出力例 3

2

Score : 400 points

Problem Statement

KEYENCE has N departments, where A_i employees belong to the i-th department (1 \leq i \leq N). No employee belongs to multiple departments.

The company is planning cross-departmental projects. Each project will be composed of exactly K employees chosen from K distinct departments.

At most how many projects can be made? No employee can participate in multiple projects.

Constraints

  • 1 \leq K \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^{12}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the maximum possible number of projects.


Sample Input 1

3 3
2 3 4

Sample Output 1

2

There can be two projects, each composed of three employees from distinct departments.


Sample Input 2

4 2
1 1 3 4

Sample Output 2

4

Sample Input 3

4 3
1 1 3 4

Sample Output 3

2
H - Bad Juice

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 425

問題文

この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。

1 から N の番号がついた N 本のジュースがあります。 このうちちょうど 1 本が腐っていることが判明しました。 そのジュースを微量でも飲むと、翌日お腹を壊してしまいます。

高橋君は翌日までに腐ったジュースを特定しなければなりません。 高橋君はそのために必要な最小の数の友人を呼び、それぞれに N 本のジュースのうちの一部を振る舞うことにしました。 各友人には何本でもジュースを与えることができ、各ジュースは何人の友人にでも与えることができます。

呼ぶ友人の数とジュースの与え方を出力して、翌日に各友人がお腹を壊したかどうかの情報を受け取り、腐ったジュースの番号を出力してください。

制約

  • N は整数
  • 2 \leq N \leq 100

入出力

この問題はインタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。

対話を行う前にジャッジは、腐ったジュースの番号 X として 1 以上 N 以下の整数を秘密裏に選択します。 X の値はあなたには与えられません。また、対話の途中で X の値が制約および以前の出力に矛盾しない範囲で変わる場合があります。

まず、ジャッジから N が入力から与えられます。

N

あなたは呼ぶ友人の数 M を出力し改行してください。

M

さらに、あなたは次に述べる M 回の出力からなる手続きを行ってください。 i = 1, 2, \ldots, M について i 回目の出力では、 i 番目の友人に飲ませるジュースの本数 K_i および、それら K_i 本のジュースの番号を昇順に並べた列 A_{i, 1}, A_{i, 2}, \ldots, A_{i, K_i} を下記の形式で空白区切りで出力し、改行してください。

K_i A_{i, 1} A_{i, 2} \ldots A_{i, K_i}

その後ジャッジから、各友人が翌日にお腹を壊したかどうかの情報が、01 のみからなる長さ M の文字列 S として与えられます。

S

i = 1, 2, \ldots, M について、Si 文字目が 1 のとき、かつそのときに限り、i 番目の友人がお腹を壊したことを表します。

それに対し、あなたは腐ったジュースの番号 X' を出力し、改行してください。

X'

その後、直ちにプログラムを終了してください。

あなたが出力した MN 本のジュースから腐ったジュースを特定するために必要な最小の友人の数であり、かつ、あなたが出力した X' が腐ったジュースの番号 X と一致していれば、正解となります。

注意点

  • 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
  • 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。 特に、プログラムの実行中に実行時エラーが起こった場合に、ジャッジ結果が ではなく TLE になる可能性があることに注意してください。
  • X' を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
  • この問題のジャッジはアダプティブです。つまり、制約および以前の出力に矛盾しない範囲で X の値が変わる場合があります。

入出力例

以下は、N = 3 の場合の入出力例です。

入力 出力 説明
3 ジュースの本数 N が与えられます。
2 呼ぶ友人の数 M を出力します。
2 1 2 1 人目の友人にジュース 1 とジュース 2 を与えます。
1 2 2 人目の友人に、ジュース 2 を与えます。
10 翌日に各友人がお腹を壊したかどうかを表す文字列 S が与えられます。
1 腐ったジュースの番号を出力します。

Score: 425 points

Problem Statement

This is an interactive problem (a type of problem where your program interacts with the judge program through Standard Input and Output).

There are N bottles of juice, numbered 1 to N. It has been discovered that exactly one of these bottles has gone bad. Even a small sip of the spoiled juice will cause stomach upset the next day.

Takahashi must identify the spoiled juice by the next day. To do this, he decides to call the minimum necessary number of friends and serve them some of the N bottles of juice. He can give any number of bottles to each friend, and each bottle of juice can be given to any number of friends.

Print the number of friends to call and how to distribute the juice, then receive information on whether each friend has an upset stomach the next day, and print the spoiled bottle's number.

Constraints

  • N is an integer.
  • 2 \leq N \leq 100

Input/Output

This is an interactive problem (a type of problem where your program interacts with the judge program through Standard Input and Output).

Before the interaction, the judge secretly selects an integer X between 1 and N as the spoiled bottle's number. The value of X is not given to you. Also, the value of X may change during the interaction as long as it is consistent with the constraints and previous outputs.

First, the judge will give you N as input.

N

You should print the number of friends to call, M, followed by a newline.

M

Next, you should perform the following procedure to print M outputs. For i = 1, 2, \ldots, M, the i-th output should contain the number K_i of bottles of juice you will serve to the i-th friend, and the K_i bottles' numbers in ascending order, A_{i, 1}, A_{i, 2}, \ldots, A_{i, K_i}, separated by spaces, followed by a newline.

K_i A_{i, 1} A_{i, 2} \ldots A_{i, K_i}

Then, the judge will inform you whether each friend has a stomach upset the next day by giving you a string S of length M consisting of 0 and 1.

S

For i = 1, 2, \ldots, M, the i-th friend has a stomach upset if and only if the i-th character of S is 1.

You should respond by printing the number of the spoiled juice bottle X', followed by a newline.

X'

Then, terminate the program immediately.

If the M you printed is the minimum necessary number of friends to identify the spoiled juice out of the N bottles, and the X' you printed matches the spoiled bottle's number X, then your program is considered correct.

Notes

  • Each output should end with a newline and flushing Standard Output. Otherwise, you may receive a TLE verdict.
  • The verdict is indeterminate if your program prints an invalid output during the interaction or terminates prematurely. In particular, note that if a runtime error occurs during the execution of the program, the verdict may be or TLE instead of .
  • Terminate the program immediately after printing X'. Otherwise, the verdict is indeterminate.
  • The judge for this problem is adaptive, meaning that the value of X may change as long as it is consistent with the constraints and previous outputs.

Sample Input/Output

Below is an interaction with N = 3.

Input Output Description
3 The number of bottles, N, is given.
2 Print the number of friends to call, M.
2 1 2 Serve juice 1 and juice 2 to the first friend.
1 2 Serve juice 2 to the second friend.
10 The string S is given, indicating whether each friend has a stomach upset the next day.
1 Print the spoiled bottle's number.
I - S = 1

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 525

問題文

整数 X, Y が与えられます。X, YX \neq 0Y \neq 0 の少なくとも一方を満たします。
次の条件を全て満たす整数の組 (A, B) を発見してください。そのような整数の組が存在しない場合はそれを報告してください。

  • -10^{18} \leq A, B \leq 10^{18}
  • xy 平面上の点 (0, 0), (X, Y), (A, B) を頂点とする三角形の面積は 1

制約

  • -10^{17} \leq X, Y \leq 10^{17}
  • (X, Y) \neq (0, 0)
  • X, Y は整数

入力

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

X Y

出力

条件を満たす整数の組 (A, B) が存在する場合は以下の形式で出力せよ。

A B

条件を満たす整数の組 (A, B) が存在しない場合は -1 を出力せよ。


入力例 1

3 5

出力例 1

1 1

(0, 0), (3, 5), (1, 1) を頂点とする三角形の面積は 1 です。よって (A, B) = (1, 1) は条件を満たします。


入力例 2

-2 0

出力例 2

0 1

入力例 3

8752654402832944 -6857065241301125

出力例 3

-1

Score: 525 points

Problem Statement

You are given integers X and Y, which satisfy at least one of X \neq 0 and Y \neq 0.
Find a pair of integers (A, B) that satisfies all of the following conditions. If no such pair exists, report so.

  • -10^{18} \leq A, B \leq 10^{18}
  • The area of the triangle with vertices at points (0, 0), (X, Y), (A, B) on the xy-plane is 1.

Constraints

  • -10^{17} \leq X, Y \leq 10^{17}
  • (X, Y) \neq (0, 0)
  • X and Y are integers.

Input

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

X Y

Output

If there is a pair of integers (A, B) that satisfies the conditions, print it in the following format:

A B

Otherwise, print -1.


Sample Input 1

3 5

Sample Output 1

1 1

The area of the triangle with vertices at points (0, 0), (3, 5), (1, 1) is 1. Thus, (A, B) = (1, 1) satisfies the conditions.


Sample Input 2

-2 0

Sample Output 2

0 1

Sample Input 3

8752654402832944 -6857065241301125

Sample Output 3

-1