time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.

Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles.

Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn’t know how to act optimally and asks for your help.

Input

First line of the input contains a single integer n (1 ≤ n ≤ 1018) — the number of rubles Kolya has at the beginning.

Then follow three lines containing integers a, b and c (1 ≤ a ≤ 1018, 1 ≤ c < b ≤ 1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.

Output

Print the only integer — maximum number of liters of kefir, that Kolya can drink.

Examples

input

10

11

9

8

output

2

input

10

5

6

1

output

2

Note

In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.

In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir.

【题目链接】: http://codeforces.com/contest/625/problem/A

【题解】



按照常识进行贪心即可。这种题不用着急的。慢慢来就能写出来.

    if (a>=b)
{
只买b就好;
剩下的钱也一直买B,如果不能买就停止
}
if (a<b)
{
看看b-c是不是小于等于a;
如果b-c>=a
只买a;
如果b-c<a
{
if (n>=b)
{
就全都买b看看还剩多少钱.
如果能买a就用剩下的钱买a;
}
else
{
只买a;
}
}
}

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); LL n;
LL a,b,c; int main()
{
//freopen("F:\\rush.txt","r",stdin);
rel(n);rel(a);rel(b);rel(c);
LL ans = 0;
if (a>=b)//b比较便宜
{
if (n>=b)
{
LL numb = ((n-b)/(b-c))+1;
//就一直买b
ans += numb;
}
else
ans = 0;
}
else if (a<b)//a比较便宜
{
if (b-c>=a)//如果买b每次实际消耗和a一样,那句直接买a就好
{
ans = n/a;
}
else
if (b-c<a)//如果买b每次实际消耗更少
{
if (n>=b)
{
LL numb = ((n-b)/(b-c))+1;
//就一直买b
ans += numb;
n-=numb*(b-c);
}
else
ans = 0;
ans += n/a;//剩下有钱再买a
}
}
cout << ans <<endl;
return 0;
}

【15.07%】【codeforces 625A】Guest From the Past的更多相关文章

  1. 【CodeForces 625A】Guest From the Past

    题 题意 一升奶可以花费a元,也可以话b元买然后获得c元,一开始有n元,求最多买多少升奶. 分析 贪心,如果b-c<a,且n≥b,那就买b元的,n先减去b再看看够买多少瓶,然后再+1瓶,余款再购 ...

  2. 【黑金教程笔记之008】【建模篇】【Lab 07 数码管电路驱动】—笔记

    实验七的目的是设计实现最大为99数字在2个数码管上.采用同步动态扫描.即行信号和列信号同步扫描.这里数码管是共阳极的.选择端口也是共阳极的. 模块: /************************ ...

  3. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  4. 【42.07%】【codeforces 558A】Lala Land and Apple Trees

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【17.07%】【codeforces 583D】Once Again...

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 758D】Ability To Convert

    [题目链接]:http://codeforces.com/contest/758/problem/D [题意] 给你一个n进制的数k; 问你它可能的最小的十进制数是多少; [题解] 从右往左; 获取数 ...

  7. 【codeforces 379D】New Year Letter

    [题目链接]:http://codeforces.com/contest/379/problem/D [题意] 让你构造出两个长度分别为n和m的字符串s[1]和s[2] 然后按照连接的规则,顺序连接s ...

  8. 【42.59%】【codeforces 602A】Two Bases

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. 控制面板项 .cpl 文件说明

    控制面板项 .cpl 文件说明 appwiz.cpl               程序和功能.卸载或更改程序 bthprops.cpl             蓝牙控制面板 desk.cpl      ...

  2. values-dimen 不同分辨率资源实现引用

    今天遇到了一种情况,就是在不同分辨率下面出现了需要设定不同的距离,当时第一反映就是重新定义一个layout.但是,仅仅为了更改一个数值就复制那么多的代码,明显不合里.后来就想到干脆在不同的分辨率下创建 ...

  3. PHP类中的__get()和__set函数到底有什么用

    PHP类中的__get()和__set函数到底有什么用 一.总结 一句话总结:当试图获取一个不可达变量时,类会自动调用__get.同样的,当试图设置一个不可达变量时,类会自动调用__set.在网站中, ...

  4. Linux启动(续)

    runlevel (启动级别):    查看命令 :who -r 或 runlevel         0:halt 关机         1:单用户模式,直接以管理员身份登录,不需要密码       ...

  5. 怎样 TabHostFragment自己定义 tab键(indicator)

    1 获得 tabHostFragment: ActionBarActivity activity2 = (ActionBarActivity) activity; mTabHost = new Fra ...

  6. 【JavaScript】--JavaScript总结一览无余

    对于 北风网李炎恢老师的JavaScript的视频也真的是醉了.视频整体来说结构清晰.内容比較简单.JS是一种灵活,开放的语言,语法规则并没有那么的死板.非常easy让人接受. JS的基础部分跟C#类 ...

  7. WebStorm(Amaze开发工具)--JavaScript 开发工具

    WebStorm(Amaze开发工具)--JavaScript 开发工具 一.总结 1.webstorm:前段开发神器,应该比sublime好用. 2.webstorm功能:支持显示图片宽高,标签重构 ...

  8. [D3] Animate Chart Axis Transitions in D3 v4

    When the data being rendered by a chart changes, sometimes it necessitates a change to the scales an ...

  9. [D3] Build a Line Chart with D3 v4

    Line charts are often used to plot temporal data, like a stock price over time. In this lesson we’ll ...

  10. μC/OS中的任务就绪表

    为了便于对就绪表的查找,μC/OSII又定义了一个数据类型为INT8U的变量OSRdyGrp, 并使该变量的每一位都对应OSRdyTbl[ ]的一个任务组(即数组的一个元素),如果某任务组中 有任务就 ...