50求助
  • 板块P9519 pay
  • 楼主Pink_Cut_Tree
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/13 08:23
  • 上次更新2023/11/3 04:10:08
查看原帖
50求助
793625
Pink_Cut_Tree楼主2023/8/13 08:23

以为能70

#include<iostream>
#include<cmath>
using namespace std;
#define int long long
int n,m,a[1000006],b[1000006],happy,maxx=-0x7f;
bool prize[1000006];
bool check(int x){
	for(int i=1;i<=n;i++){ //依次枚举每一个员工 
		happy=0;
		for(int j=max(i-x,0ll);j<=i+x;j++){
			if(j>n){
				break;
			}
			if(prize[j]){
				happy+=(x-abs(i-j));
			}
		}
		if(happy<a[i]){
			return 1;
		}
	}
return 0;
}
signed main(){
    ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		maxx=max(maxx,a[i]);
	}
	for(int i=1;i<=m;i++){
		cin>>b[i];
		prize[b[i]]=1;
	}
	int l=1,r=maxx,mid,ans;
	while(l<=r){
		mid=((r-l)>>1)+l;
		if(check(mid)){
			l=mid+1,ans=mid;
		}
		else{
			r=mid-1;
		}
	}
	cout<<ans+1;
return 0;
}
2023/8/13 08:23
加载中...