QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 256 MB 총점: 100

#21348. 젖소 추격

통계

Farmer John이 울타리 구멍 수리를 잊어 $N$마리 $(1 \le N \le 1,000)$가 도망쳐 날뛴다! 울타리 밖 젖소마다 분당 일 달러 피해다. FJ가 각각 찾아 고삐를 달아 진정시켜 피해를 멈춰야 한다.

농장 밖 직선 도로의 서로 다른 위치에 있다. 각 젖소 $i$의 위치 $P_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.