ABC D求调
  • 板块学术版
  • 楼主wangyi_c
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/9/9 21:43
  • 上次更新2023/11/2 21:46:17
查看原帖
ABC D求调
560044
wangyi_c楼主2023/9/9 21:43
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[200010];
bool check(int wide){
	int tot=1,cnt=0;
	while(1){
		int sum=0;
		while(sum<=wide){
			if(sum==0){
				sum+=a[tot];
			}
			else sum+=a[tot]+1;
			tot++;
			if(tot==n+1) return true;
		}
		sum-=a[tot--];
		if(tot==n) return true;
	}
	return false;
}
int solve(){
	int l=1,r=1e18;
	while(l+1<r){
		int mid=l+r>>1;
		if(check(mid)) r=mid;
		else l=mid;
	}
	if(check(l)) return l;
	return r;
}
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];
	cout<<solve();
	return 0;
}

非常显眼的二分但是没调出来,样例 22 都没过qwq

2023/9/9 21:43
加载中...