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 n n classes participating in this festival, where the i i ith class has a i a_i ai students and will make b i b_i bi 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?
The first line of input consists of a single integer T T T ( 1 ≤ T ≤ 25 ) (1 \leq T \leq 25) (1≤T≤25), denoting the number of test cases.
Each test case starts with a line of a single integer n n n ( 1 ≤ n ≤ 1 0 6 ) (1 \leq n \leq 10^6) (1≤n≤106), the number of classes. For the next n n n lines, each containing two integers a , b a, b a,b ( 0 ≤ a , b ≤ 1 0 9 ) (0 \leq a, b \leq 10^9) (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 n n over all test cases does not exceed 6 × 1 0 6 6 \times 10^6 6×106.
For each test case, print the answer as a single integer in one line.
1
2
3 4
2 1
3
~~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 分 ~ 割 ~ 线 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
本来这道题是让队友做的,然后自己在做前面的C题。然而没做出来
结束后开始补题
思路吗。。。。。emmm。。。。
基本没有。。。
一开始打完输入之后,就没什么思路了。
后来,发现每个班级的最大人数是min(a[i],sumb-b[i])。当然是听老师讲过的
就开始打主要模块
for (i=1;i<=n;i++)
{
l=min(m-b[i],a[i]);
p+=l;
m-=l;
}//习惯不好 m是sumb p是ans l是当前班级最大人数
打完测试,发现不对。貌似没把第i个班之前被喝的奶茶减掉。
开始改
改完如下
for (i=1;i<=n;i++)
{
k=max(b[i]-p,(ll)0);
l=min(m-k,a[i]);
p+=l;
m-=l;
}
然后就AC啦(ヒ•ω•マ)/
完整代码
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
ll T,n,m,i,j,k,l,o,p,a[1000010],b[1000010];
int main()
{
scanf("%lld",&T);
while(T--)
{
scanf("%lld",&n);
m=0;p=0;
for (i=1;i<=n;i++)
scanf("%lld%lld",a+i,b+i),m+=b[i];
for (i=1;i<=n;i++)
{
k=max(b[i]-p,(ll)0);
l=min(m-k,a[i]);
p+=l;
m-=l;
}
printf("%lld\n",p);
}
}
把作业水完了