QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 256 MB Puntuación total: 100

#8435. 空容器

Estadísticas

河岸上有 $n$ 个空容器。第 $i$ 个容器最多能容纳 $a_i$ 升水。全能的 Ivan 需要往某个容器中装入恰好 $A$ 升水并带回家。为此,他可以执行以下操作:

  1. 从河里往某个容器中注水,直到它装满;
  2. 将某个容器中的水倒回河里,直到它变空;
  3. 将水从第 $i$ 个容器倒入第 $j$ 个容器,直到第 $i$ 个容器变空或第 $j$ 个容器装满。

现在全能的 Ivan 需要你的帮助。你需要提供一个操作序列,使得最终某个容器中恰好有 $A$ 升水。如果无法做到,请输出 $-1$。

请注意,你不需要使操作次数最少,但操作总数不得超过 $10^6$。

输入格式

第一行包含整数 $n$ 和 $A$ ($1 \le n \le 10, 1 \le A \le 5$),分别表示容器数量和所需的水量。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^4$),其中 $a_i$ 是第 $i$ 个容器的容量。

输出格式

如果不存在满足条件的方案,输出 $-1$。 否则,在第一行输出一个整数 $m$,表示操作序列的长度。接下来输出 $m$ 行,每行描述一个操作。 每个操作的描述必须以一个整数开头,指定操作类型(如题目中所述的 1、2 或 3)。对于第 1 类和第 2 类操作,后面必须跟一个整数 $k$ ($1 \le k \le n$),表示参与该操作的容器编号。对于第 3 类操作,后面必须跟两个整数 $i$ 和 $j$ ($1 \le i, j \le n, i \neq j$),表示 Ivan 应将水从第 $i$ 个容器倒入第 $j$ 个容器,直到其中一个容器变空或装满。

请参考样例以更好地理解。

样例

输入 1

2 1
5 2

输出 1

4
1 1
3 1 2
2 2
3 1 2

输入 2

4 3
1 2 1 1

输出 2

-1

在区间 $[a, b]$ 中找到一个数字,使得其各位数字之积最大。

输入格式

第一行包含两个正整数 $a$ 和 $b$ ($1 \le a \le b \le 10^{18}$),表示区间的左端点和右端点。

输出格式

输出区间 $[a, b]$ 中各位数字之积最大的那个数。如果有多个可能的答案,输出其中任意一个即可。

样例

输入 1

1 10

输出 1

9

输入 2

51 62

输出 2

59

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.