https://codeforces.com/contest/625/problem/A
아이디어 : 여전히 우물에 뛰어 드는 개구리입니다.
그러나이 질문에는 몇 가지 작은 토론이 있습니다.
모두 구매 시작
마지막 돈을 사서 b를 사거나 a를 모두 사
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL H;cin>>H;
LL a,b,c;cin>>a>>b>>c;
LL ans0=H/a;///开始全部买a
LL ans=0;
///只能拿一次的特判
if(H+(c-b)<b){
if(H>=b) ans++,H-=abs(c-b);
ans+=H/a;
}
else if(H-b>=0){
LL H1=H-b;
LL k=(H1+abs(c-b)-1)/abs(c-b);
H-=k*abs(c-b);
ans+=k;///此时再买b就会死
///再买b最后一次
LL res1=0;
LL H2=H;
res1+=H2/b; H2-=res1*abs(b-c);
res1+=H2/a;
///最后一次直接都买a
LL res2=0;
LL H3=H;
res2+=H3/a;
ans+=max(res1,res2);
}
cout<<max(ans,ans0)<<"\n";
return 0;
}