| 记录编号 | 196219 | 评测结果 | AAAAAAAAAA | 
    
        | 题目名称 | 2064.爬山 | 最终得分 | 100 | 
    
        | 用户昵称 |  devil | 是否通过 | 通过 | 
    
        | 代码语言 | C++ | 运行时间 | 0.002 s | 
    
        | 提交时间 | 2015-10-21 08:27:24 | 内存使用 | 0.31 MiB | 
    
    
    
    		显示代码纯文本
		
		#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <stack>
#include <vector>
#include <map>
#include <queue>
#include <ctime>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
const int inf=1061109567;
const int maxn=1010;
const int maxm=10000010;
const int mod=1000000007;
ll Abs(ll x) {return (x<0)?-x:x;}
int main()
{
    freopen("mountain.in","r",stdin);
    freopen("mountain.out","w",stdout);
    //clock_t st=clock();
    ll n,d,a,b;
    scanf("%lld%lld%lld%lld",&n,&d,&a,&b);
    n--;ll t=Abs(b-a);n-=(t/d);
    if(t%d==0||n&1||n==0) {printf("%lld\n",max(a,b)+d*(n/2));return 0;}
    printf("%lld\n",t-t%d+min(a,b)+d*(n/2));
    //clock_t ed=clock();
    //printf("\nTime used : %.5lf Ms\n",double(ed-st)/CLOCKS_PER_SEC);
    return 0;
}