AC题解
2023-08-26 17:53:39
发布于:广东
3阅读
0回复
0点赞
花神,你对了呀,你为啥不发题解
#include <bits/stdc++.h>
using namespace std;
#define read cin
#define written cout
bool can_repay(long long num_gallons, long long within_days, long long at_least,
long long x_val) {
long long g = 0;
while (within_days > 0 && g < num_gallons) {
long long y = (num_gallons - g) / x_val;
if (y < at_least) {
long long leftover =
((num_gallons - g) + (at_least - 1)) / at_least;
return leftover <= within_days;
}
long long max_match = num_gallons - (x_val * y);
long long num_days = std::min((max_match - g) / y + 1, within_days);
g += y * num_days;
within_days -= num_days;
}
return g >= num_gallons;
}
int main() {
long long num_gallons;
long long within_days;
long long at_least;
read >> num_gallons >> within_days >> at_least;
long long low = 1;
long long high = INT64_MAX / 2;
while (low < high) {
long mid = (low + high + 1) / 2;
if (can_repay(num_gallons, within_days, at_least, mid)) {
low = mid;
} else {
high = mid - 1;
}
}
written << low << endl;
}
这里空空如也
有帮助,赞一个