CF1902B.Getting Points

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn days, and in order not to get expelled, Monocarp has to earn at least PP points during those nn days. There are two ways to earn points — completing practical tasks and attending lessons. For each practical task Monocarp fulfills, he earns tt points, and for each lesson he attends, he earns ll points.

Practical tasks are unlocked "each week" as the term goes on: the first task is unlocked on day 11 (and can be completed on any day from 11 to nn), the second task is unlocked on day 88 (and can be completed on any day from 88 to nn), the third task is unlocked on day 1515, and so on.

Every day from 11 to nn, 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 22 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!

Monocarp 是贝尔兰国立大学的一名学生。由于贝尔兰教育体系的最新改革,Monocarp 在本学期内只需学习一门课程——编程。

整个学期共包含 nn 天,为了不被开除,Monocarp 必须在这 nn 天内至少获得 PP 分。获取分数的方式有两种:完成实践任务和参加课程。每完成一项实践任务,Monocarp 可获得 tt 分;每参加一节课,他可获得 ll 分。

实践任务按“每周”节奏逐步解锁:第 11 项任务于第 11 天解锁(可在第 11 至 nn 天中的任意一天完成),第 22 项任务于第 88 天解锁(可在第 88 至 nn 天中的任意一天完成),第 33 项任务于第 1515 天解锁,依此类推。

从第 11 天到第 nn 天,每天均安排有一节课,Monocarp 均可参加。而每一天,Monocarp 都需选择整日学习或整日休息。当 Monocarp 选择学习时,他必须参加当天的课程,并且最多可完成 22 项已解锁且尚未完成的实践任务;若 Monocarp 选择整日休息,则跳过当天课程,且忽略所有实践任务。

Monocarp 希望拥有尽可能多的休息日,即最大化其休息天数。请帮助他计算他最多可以休息多少天!

输入格式

The first line contains a single integer tctc (1≤tc≤1041 \le tc \le 10^4) — the number of test cases. The description of the test cases follows.

The only line of each test case contains four integers nn, PP, ll and tt (1≤n,l,t≤1091 \le n, l, t \le 10^9; 1≤P≤10181 \le P \le 10^{18}) — 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.

第一行包含一个整数 tctc(1≤tc≤1041 \le tc \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅一行,包含四个整数 nn、PP、ll 和 tt(1≤n,l,t≤1091 \le n, l, t \le 10^9;1≤P≤10181 \le P \le 10^{18}),分别表示天数、Monocarp 需要获得的最低总分、出席一节课所得分数以及完成一项任务所得分数。

保证对于每个测试用例,若 Monocarp 出席所有课程并完成所有任务,则一定不会被开除。

输出格式

For each test, print one integer — the maximum number of days Monocarp can rest without being expelled from University.

对于每次测试,输出一个整数——Monocarp 在不被大学开除的情况下最多可以休息的天数。

输入输出样例

  • 输入#1

    5
    1 5 5 2
    14 3000000000 1000000000 500000000
    100 20 1 10
    8 120 10 20
    42 280 13 37

    输出#1

    0
    12
    99
    0
    37

说明/提示

In the first test case, the term lasts for 11 day, so Monocarp should attend at day 11. Since attending one lesson already gives 55 points (5≥P5 \ge P), so it doesn't matter, will Monocarp complete the task or not.

In the second test case, Monocarp can, for example, study at days 88 and 99: at day 88 he will attend a lesson for 10910^9 points and complete two tasks for another 5⋅108+5⋅1085 \cdot 10^8 + 5 \cdot 10^8 points. And at day 99 he only attends a lesson for another 10910^9 points.

In the third test case, Monocarp can, for example, study at day 4242: attending a lesson gives him 11 point and solving 22 out of 66 available tasks gives him another 2⋅102 \cdot 10 points.

In the fourth test case, Monocarp has to attend all lessons and complete all tasks to get 8⋅10+2⋅20=1208 \cdot 10 + 2 \cdot 20 = 120 points.

In the fifth test case, Monocarp can, for example, study at days: 88 — one lesson and first and second tasks; 1515 — one lesson and the third task; 2222 — one lesson and the fourth task; 2929 — one lesson and the fifth task; 3636 — one lesson and the sixth task.

在第一个测试用例中,学期持续 11 天,因此 Monocarp 应在第 11 天参加课程。由于仅参加一节课即可获得 55 分(5≥P5 \ge P),因此 Monocarp 是否完成任务已无关紧要。

在第二个测试用例中,Monocarp 可以例如在第 88 天和第 99 天学习:在第 88 天,他参加一节价值 10910^9 分的课程,并完成两项任务,额外获得 5⋅108+5⋅1085 \cdot 10^8 + 5 \cdot 10^8 分;而在第 99 天,他仅参加一节价值 10910^9 分的课程。

在第三个测试用例中,Monocarp 可以例如在第 4242 天学习:参加一节课获得 11 分,从当前可选的 66 项任务中完成其中 22 项,额外获得 2⋅102 \cdot 10 分。

在第四个测试用例中,Monocarp 必须参加全部 88 节课并完成全部 22 项任务,才能获得 8⋅10+2⋅20=1208 \cdot 10 + 2 \cdot 20 = 120 分。

在第五个测试用例中,Monocarp 可以例如在以下日期学习:第 88 天——参加一节课并完成第一、二项任务;第 1515 天——参加一节课并完成第三项任务;第 2222 天——参加一节课并完成第四项任务;第 2929 天——参加一节课并完成第五项任务;第 3636 天——参加一节课并完成第六项任务。

输入解题思路,AI测评打分。不知道怎么写?

首页