問題一覧 > 通常問題

No.54 Happy Hallowe'en

レベル : / AI推定難易度 : 1575 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 111
作問者 : なお
お気に入りにしたユーザー ProblemId : 41 / 自分の提出
問題文最終更新日: 2026-06-26 11:19:06
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 45 (順位表) の他の問題:

Problem Statement

Today is Halloween, so Taro has decided to visit the houses in his neighborhood to get candy.

There are \(N\) houses in the neighborhood other than Taro's own.
Visiting house \(i\) gives him \(V_i\) pieces of candy, but
in order to distribute candy fairly among the neighborhood children,
if he already has \(T_i\) or more pieces of candy, he receives no candy at all.

Taro initially has no candy and can visit the neighborhood houses in any order he likes.
Find the maximum number of pieces of candy Taro can receive.
Each house can be visited only $1$ time.

Input

\(N\)
\(V_1\ T_1\)
\(V_2\ T_2\)
\(\dots\)
\(V_i\ T_i\)
\(\dots\)
\(V_N\ T_N\)

Line \(1\) contains an integer \(N\ (1 \leq N \leq 10000)\), the number of houses in the neighborhood.
Each of the following \(N\) lines contains, separated by a space, an integer \(V_i\ (1 \leq V_i \leq 10000)\), the number of pieces of candy received at house \(i\) \((1 \leq i \leq N)\), and
an integer \(T_i\ (1 \leq T_i \leq 10000)\), the threshold for receiving candy.

Output

Output the maximum number of pieces of candy Taro can receive.
Print a newline at the end.

Sample

Sample 1
Input
3
1 1
3 2
5 3
Output
6

If he visits house \(1\), he has \(0\) pieces of candy, so he receives \(1\) piece.
If he then visits house \(2\), he has \(1\) piece of candy, so he would receive \(3\) pieces, but
visiting house \(3\) instead gives him \(5\) pieces, so he can receive at most \(1+5=6\) pieces.

Sample 2
Input
5
1 1
1 4
1 2
1 5
1 3
Output
5

By visiting all the houses in an appropriate order, he can receive at most \(5\) pieces of candy.

Sample 3
Input
7
2 1
2 3
9 2
3 1
6 4
3 5
4 8
Output
11

He visits houses \(1,2,6,7\) in this order, receiving \(2,2,3,4\) pieces of candy, respectively.

Sample 4
Input
2
1 3
100 2
Output
101

Provided by sugim.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。