题目有贪心的解,这里提供二分。首先列出当前天数能否完成任务不挂科,然后判断。这里有个细节,我们二分的目的是求解当前尽可能的小的右端点,所以判断条件后面利用的是r=mid+1,每次更新ans
#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define int long long
void solve(){
int n, p, l, t;
cin >> n >> p >> l >> t;
int lf = 0, ri = n;
function<bool(int)>check=[&](int mid)->bool{
int tmp = l * mid + min((2*mid), (n+6)/7)*t;
return tmp>=p;
};
int ans = n;
while(lf <= ri) {
int mid = lf+ri>>1;
if(check(mid)) {
ri = mid - 1;
ans = min(ans,mid);
} else lf = mid + 1;
}
cout << n-ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}