CF1183C.Computer Game
普及/提高-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vova is playing a computer game. There are in total n turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is k.
During each turn Vova can choose what to do:
- If the current charge of his laptop battery is strictly greater than a, Vova can just play, and then the charge of his laptop battery will decrease by a;
- if the current charge of his laptop battery is strictly greater than b (b<a), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by b;
- if the current charge of his laptop battery is less than or equal to a and b at the same time then Vova cannot do anything and loses the game.
Regardless of Vova's turns the charge of the laptop battery is always decreases.
Vova wants to complete the game (Vova can complete the game if after each of n turns the charge of the laptop battery is strictly greater than 0). Vova has to play exactly n turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all.
Your task is to find out the maximum possible number of turns Vova can just play (make the first type turn) or report that Vova cannot complete the game.
You have to answer q independent queries.
沃瓦正在玩一款电脑游戏。游戏总共包含 n 个回合,沃瓦非常希望完成全部回合。他的笔记本电脑电池初始电量(即游戏开始前的电量)为 k。
在每个回合中,沃瓦可以选择以下操作之一:
- 若当前电池电量严格大于 a,则沃瓦可以仅玩游戏,之后电池电量减少 a;
- 若当前电池电量严格大于 b(其中 b<a),则沃瓦可以边玩游戏边充电,之后电池电量减少 b;
- 若当前电池电量小于等于 a 且 同时小于等于 b,则沃瓦无法进行任何操作,游戏失败。
无论沃瓦选择哪种操作,电池电量始终会下降。
沃瓦希望成功完成整个游戏(即:在全部 n 个回合结束后,每回合结束时的电池电量均严格大于 0)。沃瓦必须恰好进行 n 个回合。在所有能成功完成游戏的方案中,沃瓦希望最大化“仅玩游戏”(第一类操作)的回合数。也有可能沃瓦根本无法完成游戏。
你的任务是:求出沃瓦最多能进行多少次“仅玩游戏”的操作(即第一类操作),或者判定沃瓦无法完成游戏。
你需要回答 q 个相互独立的查询。
输入格式
The first line of the input contains one integer q (1≤q≤105) — the number of queries. Each query is presented by a single line.
The only line of the query contains four integers k,n,a and b (1≤k,n≤109,1≤b<a≤109) — the initial charge of Vova's laptop battery, the number of turns in the game and values a and b, correspondingly.
输入的第一行包含一个整数 q(1≤q≤105),表示查询次数。每次查询由单独一行给出。
每次查询的唯一一行包含四个整数 k,n,a 和 b(1≤k,n≤109, 1≤b<a≤109),分别表示 Vova 笔记本电脑电池的初始电量、游戏的回合数,以及数值 a 和 b。
输出格式
For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova can just play (make the first type turn) otherwise.
对于每个查询,输出一个整数:如果沃瓦无法完成游戏,则输出 −1;否则输出沃瓦最多可以进行的回合数(即执行第一类操作的次数)。
输入输出样例
输入#1
6 15 5 3 2 15 5 4 3 15 5 2 1 15 5 5 1 16 7 5 2 20 5 7 3
输出#1
4 -1 5 2 0 1
说明/提示
In the first example query Vova can just play 4 turns and spend 12 units of charge and then one turn play and charge and spend 2 more units. So the remaining charge of the battery will be 1.
In the second example query Vova cannot complete the game because even if he will play and charge the battery during each turn then the charge of the laptop battery will be 0 after the last turn.
在第一个示例查询中,Vova 可以直接进行 4 轮游戏,消耗 12 单位电量,然后进行一轮“游戏并充电”,再消耗 2 单位电量。因此,电池剩余电量为 1。
在第二个示例查询中,Vova 无法完成游戏,因为即使他在每一轮都选择“游戏并充电”,笔记本电脑电池的电量也将在最后一轮结束后变为 0。
输入解题思路,AI测评打分。不知道怎么写?