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

Note

יש $4$ מדידות, גבול $20$, ערכים לפי הסדר $10$, $3$, $20$, $40$.

בחירת מדידות $2$ ו־$4$ מיטבית, שגיאה $17$. בראשונה השגיאה $2\times |10-3| = 14$, בשלישית $|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.