F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Roundgod and Milk Tea

Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2189    Accepted Submission(s): 936


Problem Description
Roundgod is a famous milk tea lover at Nanjing University second to none. This year, he plans to conduct a milk tea festival. There will be $n$ classes participating in this festival, where the $i$th class has $a_i$ students and will make $b_i$ cups of milk tea.

Roundgod wants more students to savor milk tea, so he stipulates that every student can taste at most one cup of milk tea. Moreover, a student can't drink a cup of milk tea made by his class. The problem is, what is the maximum number of students who can drink milk tea?
 

Input
The first line of input consists of a single integer $T$ $(1 \leq T \leq 25)$, denoting the number of test cases.

Each test case starts with a line of a single integer $n$ $(1 \leq n \leq 10^6)$, the number of classes. For the next $n$ lines, each containing two integers $a, b$ $(0 \leq a, b \leq 10^9)$, denoting the number of students of the class and the number of cups of milk tea made by this class, respectively.

It is guaranteed that the sum of $n$ over all test cases does not exceed $6 \times 10^6$.
 

Output
For each test case, print the answer as a single integer in one line.
 

Sample Input
1 2 3 4 2 1
 

Sample Output
3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 03:00:46, Gzip enabled