95分代码求条(有注释)
查看原帖
95分代码求条(有注释)
1046320
panbojun楼主2024/8/22 11:27

真找不出来问题了,longlong也过不去

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long k, d, n, a[N];
bool check(int x, int zz){ 
	int step = 1, cnt = x, now = zz;
	//step表示目前修到的任务
	//cnt表示目前机子数量
	//now表示现在的时间
	//(zz是第一个任务接到的时间)
	while(step <= n){ 
		if(a[step] + d >= now){ 
		//如果现在的任务没有超时 
			cnt --; step ++;
		//花一个机子修,并换下一个 
		} else { 
			return 0;
		//超时直接失败 
		} 
		if(cnt == 0) { 
		//如果现在的机子修完了 
			cnt = x; now ++;
		//只能等下一天修,并且机子全部恢复
		//所以最开始的判断不需要判 cnt > 0
		} 
	} 
	//如果最后一个任务都能修完直接成功 
	return 1;
} 
signed main(){ 
	cin >> k >> d >> n;
	for(int i = 1; i <= n; i++){cin >> a[i];} 
	sort(a + 1, a + 1 + n);
	int l = 0, r = n + 1, mid, t = a[1];
	while(l + 1 < r){ 
		mid = l + r >> 1;
		if(check(mid, t)) r = mid;
		else l = mid;
	} 
	cout << r << '\n';
	return 0;
} 
2024/8/22 11:27
加载中...