QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22376. 気圧を調べる牛

Statistics

増乳に関する雑誌記事を受け、Bessie は Farmer John に気に入られるため気圧を研究する牛になりました。

一日に $N$ 回($(1 \le N \le 100)$)測り、$M_{1}$ から $M_{N}$ と名付けます($(1 \le M_{i} \le 1,000,000)$)。番号は観測順です。

一日の気圧全体を正確に表す部分集合を選びます。$K$ 個($(1 \le K \le N)$)の添字 $s_{j}$ で $1 \le s_1 < s_2 < \cdots < s_K \le N$ を満たし、以下の誤差を抑えます。

部分集合の先頭より前、連続する二項の間、末尾より後の各測定に誤差があります。$s_{j}$ の集合の総誤差は個々の誤差の和です。

具体的に、添字 $i$ が $s_{j}$ に含まれない測定では:

  • $i$ が $s_1$ 未満なら誤差は:

$$ 2 * | M_i - M_{s_1} | $$

  • $i$ が $s_j$ と $s_{j+1}$ の間なら誤差は:

$$ | 2 * M_i - \operatorname{Sum}(s_j, s_{j+1}) | $$

ここで $\operatorname{Sum}(x, y) = M_x + M_y$;

  • $i$ が $s_K$ より大きければ誤差は:

$$ 2 * | M_i - M_{s_K} | $$

最大誤差 $E$($(1 \le E \le 1,000,000)$)が与えられます。誤差が $E$ 以下の最小部分集合の大きさを求めてください。

入力

  • 第 $1$ 行:空白区切り整数 $N$ と $E$。

  • 第 $2,\ldots,N+1$ 行:第 $i+1$ 行に整数 $M_{i}$。

出力

  • 第 $1$ 行:空白区切り二整数、誤差 $E$ 以下の最小部分集合の大きさと、その大きさで達成できる最小誤差。

入出力例

入力 1

4 20
10
3
20
40

出力 1

2 17

注記

測定は $4$ 回、最大誤差 $20$、順に $10$、$3$、$20$、$40$。

第 $2$、$4$ 回を選ぶと最適で誤差 $17$。第 $1$ 項は $2\times |10-3| = 14$、第 $3$ 項は $|2\times 20 - (3+40)| = 3$。

問題作成者:Jeffrey Wang、2007

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.