QOJ.ac

QOJ

Límite de tiempo: 4 s Límite de memoria: 512 MB Puntuación total: 100

#4207. 振奋人心的远足

Estadísticas

你抵达当天的那些活动是一个让你重新熟悉(当代)艺术的好机会。不仅如此:你听到的传闻显示,你感兴趣的艺术收藏品被存放在波罗的海附近一个秘密的水下金库中,该金库属于吕贝克的一个古老粮商家族!出于对过去艺术大盗生涯的怀念,你决定将潜入这个金库作为下午的休闲活动。

这里肯定隐藏着关于网络钓鱼(phishing)的双关语,但老实说,我们对此一窍不通。

为了潜入金库,你想使用你新买的潜水艇。不幸的是,当你试图从犯罪现场逃离时,你的潜水艇需要一个非常精确的浮力值 $L$。毕竟,你可不想让你的潜水艇撞上海底,或者浮在水面上被警察轻易抓住!

为了相应地规划你的潜入行动,你需要了解金库中艺术品的浮力。凭借你的精明,你已经获得了相关信息。对于每一个可能的浮力 $\ell$,你现在都知道金库中存储了多少件浮力为 $\ell$ 的艺术品 $A_\ell$。

编写一个程序,利用这些信息计算出你可以窃取的艺术品的最大数量,使得它们的总浮力(通过将每件被窃取艺术品的浮力相加得到)恰好为 $L$,或者判定这是不可能的。

输入格式

输入的第一行包含两个整数 $M$ 和 $L$,表示金库中每件艺术品的浮力在 $-M$ 到 $M$ 之间(包含边界),且所需的总浮力为 $L$。

下一行包含 $2M + 1$ 个整数 $A_{-M}, \dots, A_M$,其中 $A_\ell$ 描述了金库中浮力为 $\ell$ 的艺术品的数量。

输出格式

你的程序应输出一行。该行应包含一个整数,即你可以窃取的艺术品的最大数量,使得它们的总浮力恰好为 $L$;如果无法实现,则输出字符串 impossible

数据范围

我们始终有 $1 \le M \le 300$,$-10^{18} \le L \le 10^{18}$,且 $0 \le A_\ell \le 10^{12}$。

  • 子任务 1(5 分):$M, A_\ell \le 50$
  • 子任务 2(15 分):$M, A_\ell \le 100$
  • 子任务 3(20 分):$M \le 30$
  • 子任务 4(20 分):$M \le 50$
  • 子任务 5(20 分):$M \le 100$
  • 子任务 6(20 分):无额外限制。

此外,以下条件成立:在子任务 3 到 6 的每一项中,如果你解决了所有满足对于所有 $\ell < 0$ 都有 $A_\ell = 0$ 的测试用例,你将获得该子任务所奖励分数的 50%。在 CMS 系统中,这显示为相应子任务的“Group 1”。

样例

样例输入 1

2 5
2 3 1 1 4

样例输出 1

9

样例输入 2

3 5
3 1 0 2 0 0 2

样例输出 2

impossible

样例输入 3

1 5
0 0 6

样例输出 3

5

说明

在第一个样例中,你可以分别窃取一件浮力为 $-2, 0, 1$ 的艺术品,两件浮力为 $-1$ 的艺术品,以及四件浮力为 $2$ 的艺术品。这导致总共窃取了 $1 + 1 + 1 + 2 + 4 = 9$ 件艺术品,总浮力为 $1 \cdot (-2) + 1 \cdot 0 + 1 \cdot 1 + 2 \cdot (-1) + 4 \cdot 2 = 5$,符合要求。

在第二个样例中,无法窃取艺术品使得它们的总浮力为 $5$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.