QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB Points totaux : 100

#23879. 士多啤梨

Statistiques

題目描述

Just Oishi Ichigo 農場(以下簡稱 JOI 農場)係一個以東西走向狹長而聞名嘅士多啤梨農場,佢嘅入口位於農場嘅最西面。喺下面,我哋將由入口向東行 $k$ 米嘅位置叫做地點 $k$。

JOI 農場入面生咗 $N$ 粒士多啤梨,分別編號為 $1$ 到 $N$。所有士多啤梨喺時刻 $0$ 之前都係青色嘅。士多啤梨 $i$($1 \le i \le N$)生喺地點 $A_{i}$,到咗時刻 $T_{i}$ 就會熟透變成紅色狀態。

士多啤梨喺青色狀態下係唔可以摘嘅。即係話,士多啤梨 $i$ 直到時刻 $T_{i}$ 先至可以摘。你喺時刻 $0$ 由位於地點 $0$ 嘅農場入口出發,以最大每秒 $1$ 米嘅速度沿東西方向移動並摘士多啤梨。摘士多啤梨所需嘅時間可以忽略唔計。

給定關於士多啤梨農場嘅資訊,請編寫一個程式,求出將所有士多啤梨喺紅色狀態下摘晒之後返到入口所需時間嘅最小值。

數據範圍

  • $1 \le N \le 100\,000$。
  • $0 \le A_{i} \le 1\,000\,000\,000 (= 10^{9})$($1 \le i \le N$)。
  • $0 \le T_{i} \le 1\,000\,000\,000 (= 10^{9})$($1 \le i \le N$)。
  • 輸入嘅所有值都係整數。

輸入格式

輸入由標準輸入按以下格式給出:

N
A_1 T_1
A_2 T_2
:
A_N T_N

輸出格式

輸出 $1$ 行,代表將所有士多啤梨喺紅色狀態下摘晒之後返到入口所需時間嘅最小值。

樣例 1

輸入

10
1 3
2 1
3 4
4 1
5 5
6 9
7 2
8 6
9 5
10 3

輸出

20

如果頭 $10$ 秒行去地點 $10$,途中可以按呢個順序摘士多啤梨 $2, 4, 5, 7, 8, 9, 10$。之後用 $10$ 秒行返去地點 $0$,途中可以按呢個順序摘士多啤梨 $6, 3, 1$。咁樣就可以將全部 $10$ 粒士多啤梨都喺紅色狀態下摘晒。

樣例 2

輸入

10
0 450
5 445
10 430
15 405
20 370
25 325
30 270
35 205
40 130
45 45

輸出

450

按以下方式移動,就可以喺 $450$ 秒之內將所有士多啤梨喺紅色狀態下摘晒:

  1. 用 $45$ 秒移動到地點 $45$。呢個時候係時刻 $45$,所以可以摘士多啤梨 $10$。摘完之後用 $45$ 秒移動到地點 $0$。
  2. 之後,用 $40$ 秒移動到地點 $40$。呢個時候係時刻 $130$,所以可以摘士多啤梨 $9$。摘完之後用 $40$ 秒移動到地點 $0$。
  3. 之後,用 $35$ 秒移動到地點 $35$。呢個時候係時刻 $205$,所以可以摘士多啤梨 $8$。摘完之後用 $35$ 秒移動到地點 $0$。
  4. 之後,用 $30$ 秒移動到地點 $30$。呢個時候係時刻 $270$,所以可以摘士多啤梨 $7$。摘完之後用 $30$ 秒移動到地點 $0$。
  5. 之後,用 $25$ 秒移動到地點 $25$。呢個時候係時刻 $325$,所以可以摘士多啤梨 $6$。摘完之後用 $25$ 秒移動到地點 $0$。
  6. 之後,用 $20$ 秒移動到地點 $20$。呢個時候係時刻 $370$,所以可以摘士多啤梨 $5$。摘完之後用 $20$ 秒移動到地點 $0$。
  7. 之後,用 $15$ 秒移動到地點 $15$。呢個時候係時刻 $405$,所以可以摘士多啤梨 $4$。摘完之後用 $15$ 秒移動到地點 $0$。
  8. 之後,用 $10$ 秒移動到地點 $10$。呢個時候係時刻 $430$,所以可以摘士多啤梨 $3$。摘完之後用 $10$ 秒移動到地點 $0$。
  9. 之後,用 $5$ 秒移動到地點 $5$。呢個時候係時刻 $445$,所以可以摘士多啤梨 $2$。摘完之後用 $5$ 秒移動到地點 $0$。
  10. 啱啱好喺時刻 $450$ 到達地點 $0$,所以可以摘士多啤梨 $1$。喺摘晒所有士多啤梨嘅同時到達咗地點 $0$。

樣例 3

輸入

15
11 23
3 94
89 3
38 58
65 29
41 3
80 42
22 76
48 85
83 98
87 29
97 96
22 75
57 25
99 33

輸出

198

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.