QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#21348. ملاحقة الأبقار

İstatistikler

نسي 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$)، حيث يبدأ.

يتحرك وحدة كل دقيقة ويضع الرسن فورا. حدد ترتيب الزيارة الذي يقلل الضرر الكلي واحسب الحد الأدنى.

الإدخال

  • السطر $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.