欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1902B.Getting Points
Getting Points
Monocarp is a student at Berland State University. Due to recent changes in the Berland education system, Monocarp has to study only one subject — programming.
The academic term consists of days, and in order not to get expelled, Monocarp has to earn at least points during those days. There are two ways to earn points — completing practical tasks and attending lessons. For each practical task Monocarp fulfills, he earns points, and for each lesson he attends, he earns points.
Practical tasks are unlocked "each week" as the term goes on: the first task is unlocked on day (and can be completed on any day from to ), the second task is unlocked on day (and can be completed on any day from to ), the third task is unlocked on day , and so on.
Every day from to , there is a lesson which can be attended by Monocarp. And every day, Monocarp chooses whether to study or to rest the whole day. When Monocarp decides to study, he attends a lesson and can complete no more than tasks, which are already unlocked and not completed yet. If Monocarp rests the whole day, he skips a lesson and ignores tasks.
Monocarp wants to have as many days off as possible, i. e. he wants to maximize the number of days he rests. Help him calculate the maximum number of days he can rest!
Input
The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The only line of each test case contains four integers , , and (; ) — the number of days, the minimum total points Monocarp has to earn, the points for attending one lesson and points for completing one task.
It's guaranteed for each test case that it's possible not to be expelled if Monocarp will attend all lessons and will complete all tasks.
Output
For each test, print one integer — the maximum number of days Monocarp can rest without being expelled from University.
Note
In the first test case, the term lasts for day, so Monocarp should attend at day . Since attending one lesson already gives points (), so it doesn't matter, will Monocarp complete the task or not.
In the second test case, Monocarp can, for example, study at days and : at day he will attend a lesson for points and complete two tasks for another points. And at day he only attends a lesson for another points.
In the third test case, Monocarp can, for example, study at day : attending a lesson gives him point and solving out of available tasks gives him another points.
In the fourth test case, Monocarp has to attend all lessons and complete all tasks to get points.
In the fifth test case, Monocarp can, for example, study at days: — one lesson and first and second tasks; — one lesson and the third task; — one lesson and the fourth task; — one lesson and the fifth task; — one lesson and the sixth task.
Samples
5
1 5 5 2
14 3000000000 1000000000 500000000
100 20 1 10
8 120 10 20
42 280 13 37
0
12
99
0
37
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |