QOJ.ac

QOJ

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

#18395. 选择子序列

Estadísticas

长度为 $N$ 的数列 $A = \{a_1, a_2, a_3, \cdots, a_N\}$ 是一个首项为 $a$、公差为 $d$ 的有限等差数列。

对于正整数 $M$,求 $A$ 中和为 $M$ 的最长子序列。

子序列是指从给定数列中删除 $0$ 个或多个元素,且保持剩余元素原有顺序所得到的数列。

第一行包含四个整数 $N, a, d, M$,以空格分隔。$(1 \leq N, a, d \leq 10^6;$ $1 \leq M \leq 10^{18})$

第一行输出和为 $M$ 的 $A$ 的最长子序列的长度 $L$。

第二行输出该子序列的 $L$ 个元素,以空格分隔。若存在多种可能的答案,输出其中任意一个即可。

如果不存在这样的子序列,则在第一行输出 $-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.