| 比赛 | 20151019 | 评测结果 | |
|---|---|---|---|
| 题目名称 | 爬山 | 最终得分 | 0 |
| 用户昵称 | AAAAAAAAAA | 运行时间 | 0.000 s |
| 代码语言 | C++ | 内存使用 | 0.00 MiB |
| 提交时间 | 2015-10-22 20:29:50 | ||
#include<fstream>
using namespace std;
int main(){
ifstream fin("mountain.in");
ofstream fout("mountain.out");
long long n,d,a,b,t,ans,s;
fin>>n>>d>>a>>b;
if(a>b){
t=b;b=a;a=t;}
s=(int)((b-a)/d);
if((n-s-1)%2==0){
ans=s*d+(n-s-1)/2*d;}
if((n-s-1)%2!=0){
ans=b+(n-s-1-1)/2*d;}
fout<<ans;
fin.close();
fout.close();
return 0;
}