QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21282. إعادة تكديس القش

Statistics

طلب Farmer John الكثير من رزم القش، ويريد $N$ أكوام في دائرة ($1 \le N \le 100,000$)، في الكومة $i$ عدد $B_{i}$ رزم. لم يصغ السائق جيدًا وتذكر فقط الأكوام $N$ في دائرة. بعد التسليم تحتوي الكومة $i$ على $A_{i}$ رزم. مجموعا $A_{i}$ و$B_{i}$ متساويان بالطبع.

يريد تحويل الترتيب الحالي $A_{i}$ إلى الهدف $B_{i}$. نقل رزمة واحدة إلى كومة تبعد $x$ خطوات حول الدائرة يتطلب $x$ وحدات عمل. أوجد أقل عمل.

الإدخال

  • السطر $1$: العدد الصحيح $N$.

  • الأسطر $2..1+N$: السطر $i+1$ يحتوي $A_{i}$ و$B_{i}$ ($1 \le A_{i}, B_{i} \le 1000$).

الإخراج

أمثلة

الإدخال 1

4
7 1
3 4
9 2
1 13

الإخراج 1

13

ملاحظة

توجد $4$ أكوام فيها $7$ و$3$ و$9$ و$1$ رزم، والهدف $1$ و$4$ و$2$ و$13$.

الأدنى $13$ وحدة عمل: نقل $6$ رزم من الكومة $1$ إلى $4$، و$1$ من $3$ إلى $2$، و$6$ من $3$ إلى $4$.

مؤلف المسألة: Brian Dean، 2012

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.