QOJ.ac

QOJ

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

#21348. המרדף אחר הפרות

Estadísticas

Farmer John שכח לתקן חור בגדר ו־$N$ פרות $(1 \le N \le 1,000)$ ברחו ומשתוללות! כל פרה מחוץ לגדר גורמת דולר נזק לדקה. FJ חייב להגיע לכל אחת ולשים רתמת ראש להרגעה ולעצירת הנזק.

הפרות במיקומים שונים לאורך כביש ישר מחוץ לחווה. FJ יודע את מיקום $P_i$ של כל פרה $i$ $(-500,000 \le P_i \le 500,000, P_i \ne 0)$ יחסית לשער (מיקום $0$), שבו מתחיל.

FJ מתקדם יחידה לדקה ושם רתמה מייד. קבעו סדר ביקור למזעור הנזק הכולל וחשבו את המינימום.

קלט

  • שורה $1$: מספר פרות $N$.

  • שורות $2..N+1$: שורה $i+1$ מכילה שלם $P_i$.

פלט

  • שורה $1$: הנזק הכולל המינימלי.

דוגמאות

קלט 1

4
-2
-12
3
7

פלט 1

50

הערה

ארבע פרות ב־$-2$, $-12$, $3$, $7$.

סדר מיטבי $-2$, $3$, $7$, $-12$. מגיע ל־$-2$ אחרי $2$ דקות: נזק הפרה $2$ דולרים.

אחר כך ל־$3$ (מרחק $5$): נזקה $2 + 5 = 7$ דולרים.

עוד $4$ דקות ל־$7$: $7 + 4 = 11$ דולרים.

לבסוף $19$ דקות ל־$-12$: $11 + 19 = 30$ דולרים.

סך הכול $2 + 7 + 11 + 30 = 50$ דולרים.

מחבר הבעיה: Chris Tzamos, 2006

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.