(2020牛客暑期多校训练营)[一]Roundgod and Milk Tea

题目:
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 ith class has ai students and will make bi cups of milk tea.web

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≤T≤25), denoting the number of test cases.svg

Each test case starts with a line of a single integer n (1≤n≤106), the number of classes. For the next n lines, each containing two integers a,b (0≤a,b≤109), 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×106.
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
翻译(谷歌)以下:
Roundgod是南京大学著名的奶茶爱好者,数一数二。今年,他计划举办一次奶茶节。将有n个班级参加这个节日,第i个班级有ai学生,并将制做双杯奶茶。this

Roundgod但愿更多的学生品尝奶茶,所以他规定每一个学生最多只能品尝一杯奶茶。并且,学生不能喝他班上学的奶茶。问题是,最多能够喝奶茶的学生人数是多少?
输入项
输入的第一行包含一个整数T(1≤T≤25),表示测试用例的数量。spa

每一个测试用例均以一行整数n(1≤n≤106)(类数)开始。对于接下来的n行,每行包含两个整数a,b(0≤a,b≤109),分别表示班级的学生人数和此班级制做的奶茶杯数。翻译

保证全部测试用例的n之和不超过6×10^6。
输出量
对于每一个测试用例,在一行中将答案打印为单个整数。
样本输入
1个
2
3 4
2 1
样本输出
3
思路:
先计算出最多有几我的能喝到奶茶,而后减去每一个班级所能浪费的最大值便可
代码以下
#include
#include
using namespace std;
int n,a[1000010],b[1000010];
long long w1,w2,ans;
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
w1=0;w2=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
w1+=a[i];w2+=b[i];
}
ans=min(w1,w2);
for(int i=1;i<=n;i++) ans=min(ans,w1+w2-a[i]-b[i]);
printf("%lld\n",ans);
}
return 0;
}xml