QOJ.ac

QOJ

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

#22376. The Baric Bovine

Estadísticas

Following up on a journal article about increasing milk production, Bessie has become the Baric Bovine by studying atmospheric pressure in order to curry favor with Farmer John.

She takes $N$ $(1 \le N \le 100)$ measurements conveniently named $M_{1}$ through $M_{N}$ during the day $(1 \le M_{i} \le 1,000,000)$; these measurements are numbered in the order in which Bessie observed them.

In order to characterize the day's atmospheric pressure readings, she is interested in finding a subset of the measurements (given by the $K$ $(1 \le K \le N)$ indices $s_{j}$ where $1 \le s_1 < s_2 < \cdots < s_K \le N$) that accurately reflects the entire set, i.e., limits the error as described below.

In any subset of measurements, an error is incurred for each measurement (1) before the first member of the subset, (2) between two consecutive measurements in the subset, and (3) after the last member of the subset. The total error value for a given set of $s_{j}$ values is the sum of each of the individual errors.

Specifically, for all measurements whose index $i$ is not one of the $s_{j}$ values:

  • if $i$ is less than $s_1$, then the sample error is:

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

  • if $i$ is between $s_j$ and $s_{j+1}$, then the sample error is

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

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

  • if $i$ is greater than $s_K$, then the sample error is

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

Given a maximum error value $E$ $(1 \le E \le 1,000,000)$, determine the size of the smallest subset of measurements that produces an error of at most $E$.

Input

  • Line 1: Two space-separated integers: $N$ and $E$
  • Lines $2,\ldots,N+1$: Line $i+1$ contains a single integer: $M_{i}$

Output

  • Line 1: Two space-separated integers: the size of the smallest subset of measurements that produces an error of at most $E$ and the least possible error for the subset of that size.

Examples

Input 1

4 20
10
3
20
40

Output 1

2 17

Bessie takes four measurements; the maximum error is 20. The measurements are, in sequence: 10, 3, 20, and 40.

Choosing the second and fourth measurements is the best option, giving an error of 17. The first term's error is $2\times |10-3| = 14$; the third term's error is $|2\times 20 - (3+40)| = 3$.

Problem credits: 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.