QOJ.ac

QOJ

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

#22387. החזר חובות

Statistics

״אל תהיה לווה או מלווה״. Bessie מייחלת שהקשיבה! עם כל אחד מ-$N$ חברים היא לוותה ממנו או הלוותה לו, $(1 \le N \le 100,000)$, שמספריהם $1,\ldots,N$.

הגיע יום ההחזר. חייבים לה יותר משהיא חייבת לאחרות. הפרות בשורה ישרה, פרה $i$ במרחק $i$ מטרים מהאסם. היא תעבור, תגבה ותחזיר כסף.

יכולה לבקש מכל פרה שחייבת לה לשלם. כשמספיק כסף לחלק מחובותיה או לכולם, יכולה לשלם בכסף שזה עתה גבתה. פרה $i$ חייבת לה $D_{i}$, $(-1,000 \le D_{i} \le 1,000; D_{i} \ne 0)$. שלילי אומר להפך, Bessie חייבת לפרה.

מתחילה באסם במיקום 0. מה המרחק המינימלי לגבות הכול ולהחזיר הכול? חייבת לסיים בקצה השורה.

קלט

  • שורה 1: שלם $N$.
  • שורות $2,\ldots,N+1$: שורה $i+1$ מכילה שלם $D_{i}$.

פלט

  • שורה 1: שלם אחד, המרחק הכולל במטרים לגבייה או תשלום לכל פרה.

דוגמאות

קלט 1

5
100
-200
250
-200
200

פלט 1

9

הערה

שלוש פרות חייבות ל-Bessie והיא חייבת לשתיים. תסיים עם 150 כסף.

      100  -200  250 -200  200
 |     |     |    |    |    |
 ***>**+**>*****>**+
                   *            < ל-Bessie יש 350
             -**<***
             *                  < ל-Bessie יש 150
             ***>****>****>**+
                             *  < ל-Bessie יש 350
                       -**<***
                       *     
                       ***>***  < Bessie מסיימת עם 150*

משמאל: האסם.

מחבר הבעיה: Jarrah Lacko, 2009

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.