求助,写的和题解的思路基本一样,就是细节不一样为什么没AC
查看原帖
求助,写的和题解的思路基本一样,就是细节不一样为什么没AC
832977
Submerge69楼主2024/2/26 17:10

为啥没AC

#include<bits/stdc++.h>
using namespace std;
int n,m,a[200010],b[200010];
int t;
int check(int temp) {
	int num=0;
	for(int i=1; i<=n; i++) {
		if(a[i]+b[i]<temp) return 0;
		if(temp>a[i]) num+=temp-a[i];
		if(num>m) return 0;
	}
	t=temp;
	return 1;
}

int main() {
	scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	for(int i=1; i<=n; i++) scanf("%d",&b[i]);
	int l=0,r=600000,mid;
	while(l<=r) {
		mid=l+(r-l)/2;
		if(check(mid)) {
			l=mid+1;
		} else {
			r=mid-1;
		}
	}
	printf("%d",t);
	return 0;
}
2024/2/26 17:10
加载中...