记录编号 |
195876 |
评测结果 |
AAAAAAAAAA |
题目名称 |
爬山 |
最终得分 |
100 |
用户昵称 |
mikumikumi |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.002 s |
提交时间 |
2015-10-19 22:31:20 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
LL n,d,a,b;
void read()
{
scanf("%lld%lld%lld%lld",&n,&d,&a,&b);//lld
}
bool check(LL x)
{
LL to=(x-a);
if(to>0) to=(to-1)/d+1;
else to=(to+1)/d-1;
LL r=(x-b);
if(r>0) r=(r-1)/d+1;
else r=(r+1)/d-1;
//cout<<x<<" "<<b<<" "<<d<<" "<<to<<" "<<r<<" "<<(x-b-1)<<endl;
if(to+r<n) return 1;
return 0;
}
void work()
{
LL l=a,r=n*d+a;
while(l<r)
{
LL mid=(r+l)/2;
if(check(mid)) l=mid+1;
else r=mid;
//cout<<mid<<" "<<check(mid)<<endl;
}
while(!check(r)) r--;
printf("%lld",r);
}
int main()
{
freopen("mountain.in","r",stdin);
freopen("mountain.out","w",stdout);
read();
work();
return 0;
}