题意:有n个班级,每个班级有a[i]个人,b[i]杯奶茶
每个人至多喝一杯奶茶,且不能喝自己班的
问能喝到奶茶的最多总人数
n<=1e6,a[i],b[i]<=1e9
思路:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned int uint; 5 typedef unsigned long long ull; 6 typedef pair<int,int> PII; 7 typedef pair<ll,ll> Pll; 8 typedef vector<int> VI; 9 typedef vector<PII> VII; 10 //typedef pair<ll,ll>P; 11 #define N 1000010 12 #define M 200010 13 #define fi first 14 #define se second 15 #define MP make_pair 16 #define pb push_back 17 #define pi acos(-1) 18 #define mem(a,b) memset(a,b,sizeof(a)) 19 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++) 20 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--) 21 #define lowbit(x) x&(-x) 22 #define Rand (rand()*(1<<16)+rand()) 23 #define id(x) ((x)<=B?(x):m-n/(x)+1) 24 #define ls p<<1 25 #define rs p<<1|1 26 27 const int MOD=1e9+7,inv2=(MOD+1)/2; 28 double eps=1e-4; 29 int INF=1e9; 30 int inf=0x7fffffff; 31 int dx[4]={-1,1,0,0}; 32 int dy[4]={0,0,-1,1}; 33 34 ll a[N],b[N]; 35 36 ll read() 37 { 38 ll v=0,f=1; 39 char c=getchar(); 40 while(c<48||57<c) {if(c=='-') f=-1; c=getchar();} 41 while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar(); 42 return v*f; 43 } 44 45 void solve() 46 { 47 int n; 48 scanf("%d",&n); 49 ll s=0,ans=0; 50 rep(i,1,n) 51 { 52 a[i]=read(),b[i]=read(); 53 s+=b[i]; 54 } 55 rep(i,1,n) ans+=min(a[i],s-b[i]); 56 ans=min(ans,s); 57 printf("%I64d\n",ans); 58 } 59 60 61 62 int main() 63 { 64 int cas=read(); 65 while(cas--) solve(); 66 return 0; 67 }