CF294B.Shaass and Bookshelf

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Shaass has nn 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 ii -th book is tit_{i} and its pages' width is equal to wiw_{i} . The thickness of each book is either 11 or 22 . All books have the same page heights.

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.

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

输入格式

The first line of the input contains an integer nn , (1<=n<=100)(1<=n<=100) . Each of the next nn lines contains two integers tit_{i} and wiw_{i} denoting the thickness and width of the ii -th book correspondingly, ( 1<=ti<=2,1<=wi<=1001<=t_{i}<=2,1<=w_{i}<=100 ).

输出格式

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

输入输出样例

  • 输入#1

    5
    1 12
    1 3
    2 15
    2 5
    2 1
    

    输出#1

    5
    
  • 输入#2

    3
    1 10
    2 1
    2 4
    

    输出#2

    3
    
首页