This page is still under construction.

Parts of this page are still being built. What you see may change.

The Baric Bovine

Interview

Time limit1sMemory limit128 MB

Summary
Choose the smallest subset of N pressure readings so the total interpolation-style error stays within E, and report that size plus the least error for it.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Prefix sum, Binary search
Solved
No attempts yet

Problem

During one day Bessie takes NN atmospheric-pressure measurements and numbers them M1,M2,…,MNM_1, M_2, \dots, M_N in the order she observes them (1≤N≤1001 \le N \le 100, 1≤Mi≤1,000,0001 \le M_i \le 1{,}000{,}000).

Bessie wants a subset of the measurements — indices s1<s2<⋯<sKs_1 < s_2 < \dots < s_K (1≤K≤N1 \le K \le N) — that represents the whole set well, i.e. keeps the error defined below small.

Every index ii that is not in the subset contributes an error:

  • if i<s1i < s_1: 2⋅∣Mi−Ms1∣2 \cdot |M_i - M_{s_1}|
  • if sj<i<sj+1s_j < i < s_{j+1} for some jj: ∣2Mi−(Msj+Msj+1)∣|2 M_i - (M_{s_j} + M_{s_{j+1}})|
  • if i>sKi > s_K: 2⋅∣Mi−MsK∣2 \cdot |M_i - M_{s_K}|

The total error is the sum of these individual errors. Given a maximum error EE (1≤E≤1,000,0001 \le E \le 1{,}000{,}000), find the size of the smallest subset whose total error is at most EE.

Input

  • Line 1: two space-separated integers NN and EE.
  • Lines 2 to N+1N+1: line i+1i+1 contains the single integer MiM_i.

Output

  • Line 1: two space-separated integers — the size of the smallest subset whose total error is at most EE, and the least possible total error achievable with a subset of that size.

Hint

For example, with measurements 10,3,20,4010, 3, 20, 40, choosing the 2nd and 4th measurements is optimal and gives a total error of 1717. The measurement before the first chosen index contributes 2⋅∣10−3∣=142 \cdot |10 - 3| = 14, and the measurement between the two chosen indices contributes ∣2⋅20−(3+40)∣=3|2 \cdot 20 - (3 + 40)| = 3.

Examples1

  1. Example 1

    Input
    4 20
    10
    3
    20
    40
    
    Expected output
    2 17