QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#18395. Choosing a Subsequence

Estadísticas

A sequence $A = \{a_1, a_2, a_3, \cdots, a_N\}$ of length $N$ is a finite arithmetic progression with the first term $a$ and common difference $d$.

For a positive integer $M$, find the longest subsequence of $A$ whose sum is $M$.

A subsequence is a sequence obtained by deleting zero or more elements from the given sequence while maintaining the original order.

The first line contains four integers $N$, $a$, $d$, and $M$ separated by spaces. $(1 \leq N, a, d \leq 10^6;$ $1 \leq M \leq 10^{18})$

The first line should output the length $L$ of the longest subsequence of $A$ whose sum is $M$.

The second line should output the $L$ elements of such a subsequence, separated by spaces. If there are multiple possible answers, output any one of them.

If no such subsequence exists, output $-1$ on the first line instead.

Examples

Input 1

5 2 2 10

Output 1

2
4 6

Input 2

3 1 2 7

Output 2

-1

Note

In Example 1, the given sequence is $A = \{2, 4, 6, 8, 10\}$. Excluding the length condition, the possible candidates for $B$ are $\{10\}$, $\{2, 8\}$, and $\{4, 6\}$. Among these, the longest subsequences are $\{2, 8\}$ and $\{4, 6\}$, so either one can be output.

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.