P4058求调
  • 板块学术版
  • 楼主Loopbreak
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/26 11:21
  • 上次更新2024/5/26 13:41:28
查看原帖
P4058求调
969943
Loopbreak楼主2024/5/26 11:21

P4058第一个点WA,第16点TLE。看了讨论区,依然没有特别明白错误的点在哪

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long

ull f(ull m, ull h[], ull a[],ull n, ull len) {
	ull res = 0, temp = 0;
	for (int i = 0; i < n; i++) { 
		temp = h[i] + a[i] * m;   //经过m个月当前i树的长度
		if (temp >= len) res += temp; //算总长度
	}	
	return res;
}

int main() {
	ull n,S,L;
	cin >> n >> S >> L;
	ull h[n], a[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	//以上输入
	ull l = 0, r = 1e18, mid, ans = 0;  
	while (l <= r) {  //二分
		mid = l + (r - l) / 2;
		if (f(mid,h,a,n,L) >= S) {  //检查满足订单要求没有
			ans = mid;  //记录答案
			r = mid - 1;  //去左边
		} else {
			l = mid + 1;  //去右边
		}
	}
	cout << ans;
	return 0;
}
2024/5/26 11:21
加载中...