Codeforces Round 178 (Div. 2)
B
Shaass and Bookshelf
Codeforces
1700
原题
← AC →
翻译中…

Shaass has $*n*$ books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the $*i*$-th book is $*t*_{*i*}$ and its pages' width is equal to $*w*_{*i*}$. The thickness of each book is either $1$ or $2$. All books have the same page heights.

翻译中…

image

翻译中…

Shaass puts the books on the bookshelf in the following way. First he selects some of the books and put them vertically. Then he puts the rest of the books horizontally above the vertical books. The sum of the widths of the horizontal books must be no more than the total thickness of the vertical books. A sample arrangement of the books is depicted in the figure.

翻译中…

image

翻译中…

Help Shaass to find the minimum total thickness of the vertical books that we can achieve.

翻译中…

Input

翻译中…

The first line of the input contains an integer $*n*$, $(1 ≤ *n* ≤ 100)$. Each of the next $*n*$ lines contains two integers $*t*_{*i*}$ and $*w*_{*i*}$ denoting the thickness and width of the $*i*$-th book correspondingly, ($1 ≤ *t*_{*i*} ≤ 2, 1 ≤ *w*_{*i*} ≤ 100$).

翻译中…

Output

翻译中…

On the only line of the output print the minimum total thickness of the vertical books that we can achieve.

翻译中…

样例

Input #1
5
1 12
1 3
2 15
2 5
2 1
Output #1
5
InputCopy OutputCopy
Input #2
3
1 10
2 1
2 4
Output #2
3
InputCopy OutputCopy
题目信息
题号
294B
时间限制
1 s
内存限制
256 MB
标签
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。