QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 512 MB Puntuación total: 25

#5708. 饥饿的狐狸

Estadísticas

现在是你宠物狐狸的晚餐时间!它的餐食包含 $N$ 块饼干,第 $i$ 块饼干的温度为 $T_i$ 摄氏度。它还有一大盘水,水的温度为 $W$ 摄氏度。

在喝了一口初始的水之后,你的狐狸开始进食。每当它吃一块饼干时,其美味度等于该饼干的温度与它最后吃或喝的东西(无论是之前吃的饼干还是喝的水,以最近一次消耗的为准)的温度之差的绝对值。它可以随时喝水,也可以按任意顺序吃饼干。

根据狐狸吃饼干和喝水的顺序,所消耗饼干的总美味度可能会有所不同。请问总美味度的最小值和最大值分别是多少?

输入格式

第一行包含两个整数 $N$ ($1 \le N \le 100\,000$) 和 $W$ ($0 \le W \le 10^9$),分别表示饼干的数量和水的温度。接下来的 $N$ 行,每行包含一个整数 $T_i$ ($0 \le T_i \le 10^9$,对于 $1 \le i \le N$),表示第 $i$ 块饼干的温度。

对于至少 30% 的测试点,满足 $W = 0$。

输出格式

输出一行,包含两个整数,分别表示你的狐狸在进食过程中可以获得的最小总美味度和最大总美味度。

样例

输入 1

3 20
18
25
18

输出 1

7 16

说明 1

为了使总美味度最小,狐狸可以先喝水,吃第一块饼干,吃第三块饼干,再喝水,最后吃第二块饼干。此时它经历的温度序列为 20, 18, 18, 20, 25 摄氏度,饼干的美味度之和为 $2 + 0 + 5 = 7$。

为了使总美味度最大,狐狸可以先喝水,然后按顺序吃饼干。此时它经历的温度序列为 20, 18, 25, 18 摄氏度,饼干的美味度之和为 $2 + 7 + 7 = 16$。

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.