QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#18395. 部分列の選択

الإحصائيات

長さ $N$ の数列 $A = \{a_1, a_2, a_3, \cdots, a_N\}$ は、初項が $a$、公差が $d$ である有限等差数列である。

正の整数 $M$ に対して、和が $M$ となる $A$ の部分列のうち、最も長いものを求めよ。

部分列とは、与えられた数列から元の順序を維持したまま $0$ 個以上の要素を取り除いて得られる数列のことである。

入力

1行目に4つの整数 $N, a, d, M$ が空白区切りで与えられる。 $(1 \leq N, a, d \leq 10^6;$ $1 \leq M \leq 10^{18})$

出力

1行目に、和が $M$ となる $A$ の部分列のうち、最も長いものの長さ $L$ を出力せよ。

2行目に、そのような部分列の要素 $L$ 個を空白区切りで出力せよ。答えが複数存在する場合は、そのうちのどれを出力してもよい。

そのような部分列が存在しない場合は、1行目に $-1$ を出力せよ。

入出力例

入力 1

5 2 2 10

出力 1

2
4 6

入力 2

3 1 2 7

出力 2

-1

注記

例題1において、与えられた数列は $A = \{2, 4, 6, 8, 10\}$ である。長さの条件を除くと、考えられる部分列の候補は $\{10\}$, $\{2, 8\}$, $\{4, 6\}$ である。このうち最も長いものは $\{2, 8\}$ と $\{4, 6\}$ であるため、どちらを出力してもよい。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.