CF1902B.Getting Points

普及/提高-

通过率:0%

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!

输入格式

The first line contains a single integer tctc ( 1tc1041 \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 ( 1n,l,t1091 \le n, l, t \le 10^9 ; 1P10181 \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.

输出格式

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

输入输出样例

  • 输入#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 ( 5P5 \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 5108+51085 \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 2102 \cdot 10 points.

In the fourth test case, Monocarp has to attend all lessons and complete all tasks to get 810+220=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.

首页