显然用二分答案,重点就是check函数怎么写了,用x来表示套牌数,所以x要满足每一个x-a<=b,并且所有x-a的和要<=m.最后结果一定要开long long
`#include<stdio.h>
include<stdlib.h>
include<string.h>
include<bits/stdc++.h>
using namespace std;
int check(int *lsta,int *lstb,int n,long long m,long long k){
long long sum=0;
for(int i=0;i<n;i++){
if(k-lsta[i]>lstb[i]) return 0;
if(k>lsta[i]) sum+=k-lsta[i];
}
if(sum>m) return 0;
return 1;
}
int main(){
int n,a,b;
long long m;
scanf("%d %lld",&n,&m);
int lsta[n],lstb[n];
for(int i=0;i<n;i++){
scanf("%d",&lsta[i]);
}
for(int i=0;i<n;i++){
scanf("%d",&lstb[i]);
}
int l=0;
long long r=4e10,cnt=0;
while(l<=r){
long long k=(l+r)/2;
if(check(lsta,lstb,n,m,k)){
if(k>cnt) cnt=k;
l=k+1;
}
else r=k-1;
}
printf("%lld",cnt);
return 0;
} `