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.
Input
The first line of the input contains one integer q (1≤q≤10^5) — 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≤10^9,1≤b<a≤10^9) — the initial charge of Vova's laptop battery, the number of turns in the game and values a and b, correspondingly.
Output
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.
Example
Input
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
Output
4
-1
5
2
0
1
Note
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.

题意:电脑有电量k,游戏有有n个回合,每个回合可以不充电玩花费a,充电玩花费b,电量不得小于等于0,问能否玩完n个回合。如果可以输出最大的不充电玩的回合数,如果不行输出-1.
如果k-(n-1)b<=b,即k-nb<=0,那么无论如何都不能玩完n个回合,输出-1;
设玩了x个不充电回合,则 ax+b(n-x)<k,解得 x<(k-bn)/(a-b)
计算右边式子,然后算得最大的整数x,与n取min即为答案。
先来一段考场写的傻*二分反正也能过~~

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll q,k,n,a,b;
    cin>>q;
    while(q--)
    {
        cin>>k>>n>>a>>b;
        if(k-(n-1)*b<=b) {cout<<-1<<endl;continue;}
        ll lef=0,rig=n,mid;
        while(lef+1<rig)
        {
            int mid=(lef+rig)>>1;
            if(a*mid + b*(n-mid)<k) lef=mid;
            else rig=mid;
        }
        if(a*rig+ b*(n-rig)<k) cout<<rig<<endl;
        else cout<<lef<<endl;
    }
    return 0;
} 

这里是正解

#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long minmy(long long a,long long b)
{
    return a>b?b:a;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll q,k,n,a,b,temp;
    cin>>q;
    while(q--)
    {
        cin>>k>>n>>a>>b;
        if(k-n*b<=0) {cout<<-1<<endl;continue;}
        else
        {
            if( (k-b*n)%(a-b)==0 ) temp=(k-b*n)/(a-b)-1;
            else temp=(k-b*n)/(a-b);

            cout<<minmy(temp,n)<<endl;
        }
    }
    return 0;
}