codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1183C.md (2716B)


      1 Source: https://codeforces.com/problemset/problem/1183/C
      2 
      3 C. Computer Game
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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$.
     22 
     23 During each turn Vova can choose what to do:
     24 
     25 * 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$;
     26 * if the current charge of his laptop battery is strictly greater than $b$ ($b \lt a$), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by $b$;
     27 * 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.
     28 
     29 Regardless of Vova's turns the charge of the laptop battery is always decreases.
     30 
     31 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.
     32 
     33 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.
     34 
     35 You have to answer $q$ independent queries.
     36 
     37 Input
     38 
     39 The first line of the input contains one integer $q$ ($1 \le q \le 10^5$) — the number of queries. Each query is presented by a single line.
     40 
     41 The only line of the query contains four integers $k, n, a$ and $b$ ($1 \le k, n \le 10^9, 1 \le b \lt a \le 10^9$) — the initial charge of Vova's laptop battery, the number of turns in the game and values $a$ and $b$, correspondingly.
     42 
     43 Output
     44 
     45 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.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 6
     53 15 5 3 2
     54 15 5 4 3
     55 15 5 2 1
     56 15 5 5 1
     57 16 7 5 2
     58 20 5 7 3
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 4
     65 -1
     66 5
     67 2
     68 0
     69 1
     70 ```
     71 
     72 Note
     73 
     74 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$.
     75 
     76 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.