记录编号 196051 评测结果 AAAAAAAAAA
题目名称 爬山 最终得分 100
用户昵称 Gravatardashgua 是否通过 通过
代码语言 C++ 运行时间 0.002 s
提交时间 2015-10-20 19:19:01 内存使用 0.31 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
 
template<class Num>void read(Num &x)
{
    char c; int flag = 1;
    while((c = getchar()) < '0' || c > '9')
        if(c == '-') flag *= -1;
    x = c - '0';
    while((c = getchar()) >= '0' && c <= '9')
        x = (x<<3) + (x<<1) + (c-'0');
    x *= flag;
}
template<class Num>void write(Num x)
{
    if(!x) {putchar('0');return;}
    if(x < 0) putchar('-'), x = -x;
    static char s[20];int sl = 0;
    while(x) s[sl++] = x%10 + '0',x /= 10;
    while(sl) putchar(s[--sl]);
}
 
const double eps = 1e-6;
long long n, d, a, b;
 
int main()
{
	double x;
	
	freopen("mountain.in","r",stdin);
	freopen("mountain.out","w",stdout);
	
	read(n), read(d), read(a), read(b);
	
	x = ((double)(b - a) / d + (n + 1)) / 2;
	
	write(std::max(d * ((long long)(floor(x) + eps) - 1) + a, d * (n - (long long)(ceil(x) + eps)) + b));
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}