QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100

#21348. Kühe einfangen

统计

Farmer John hat ein Zaunloch nicht repariert. Seine $N$ Kühe $(1 \le N \le 1,000)$ sind entkommen und randalieren! Jede Kuh verursacht draußen pro Minute einen Dollar Schaden. FJ muss jede besuchen und ein Halfter anlegen, um sie zu beruhigen und den Schaden zu stoppen.

Sie stehen an verschiedenen Positionen einer geraden Straße außerhalb der Farm. FJ kennt Position $P_i$ jeder Kuh $i$ $(-500,000 \le P_i \le 500,000, P_i \ne 0)$ relativ zum Tor (Position $0$), wo er startet.

FJ geht eine Einheit pro Minute und legt Halfter sofort an. Bestimme die schadensminimierende Reihenfolge und berechne den minimalen Gesamtschaden.

Eingabe

  • Zeile $1$: Kuhanzahl $N$.

  • Zeilen $2..N+1$: Zeile $i+1$ enthält ganze Zahl $P_i$.

Ausgabe

  • Zeile $1$: minimaler Gesamtschaden.

Beispiele

Eingabe 1

4
-2
-12
3
7

Ausgabe 1

50

Hinweis

Vier Kühe bei $-2$, $-12$, $3$, $7$.

Optimale Folge $-2$, $3$, $7$, $-12$. Er erreicht $-2$ nach $2$ Minuten: $2$ Dollar Schaden dieser Kuh.

Dann nach $3$ (Distanz $5$): $2 + 5 = 7$ Dollar für diese Kuh.

Noch $4$ Minuten bis $7$: $7 + 4 = 11$ Dollar.

Zum Schluss $19$ Minuten bis $-12$: $11 + 19 = 30$ Dollar.

Gesamt $2 + 7 + 11 + 30 = 50$ Dollar.

Aufgabenautor: 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.