Covered Path

CodeForces - 534B

The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2meters per second. We know that this section of the route took exactly t seconds to pass.

Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.

Input

The first line contains two integers v1 and v2 (1 ≤ v1, v2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.

The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds.

It is guaranteed that there is a way to complete the segment so that:

  • the speed in the first second equals v1,
  • the speed in the last second equals v2,
  • the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d.

Output

Print the maximum possible length of the path segment in meters.

Examples

Input
5 6
4 2
Output
26
Input
10 10
10 0
Output
100

Note

In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.

In the second sample, as d = 0, the car covers the whole segment at constant speed v = 10. In t = 10 seconds it covers the distance of 100 meters.

sol:一开始以为是小学奥数一样的东西,写了一堆特判后发现根本讨论不完,于是彻底自闭

发现是个很裸的dp,dp[i][j]表示第 i 秒,速度为 j 的最大路程

Ps:初速度100,加速度10,加速时间100,要开1105的数组,唯一的坑点

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int v1,v2,t,d,dp[][N];
int main()
{
int i,j,k;
R(v1); R(v2); R(t); R(d);
memset(dp,-,sizeof dp);
dp[][v1]=v1;
for(i=;i<t;i++)
{
for(j=;j<=i*d+v1;j++) if(dp[i][j]!=-)
{
for(k=-d;k<=d;k++)
{
if(j+k>=) dp[i+][j+k]=max(dp[i+][j+k],dp[i][j]+j+k);
}
}
}
// for(i=1;i<=t;i++)
// {
// for(j=0;j<=v2;j++) printf("%d ",dp[i][j]); puts("");
// }
Wl(dp[t][v2]);
return ;
}
/*
Input
5 6
4 2
Output
26 Input
10 10
10 0
Output
100 Input
87 87
2 10
Output
174 Input
1 11
6 2
Output
36 Input
100 1
100 10
Output
29305 input
100 1
100 1
output
5050
*/

codeforces534B的更多相关文章

随机推荐

  1. 将Oracle 12c的某用户数据迁移至OracleXE的用户

    前言:OracleXE全称为oracle database 11g express edition .Oracle Database 11g Express Edition是 Oracle 数据库的免 ...

  2. Vue-插槽学习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Linux 修改时间和时区为上海时区

    发现centos7的时间是utc的,和上海时间不一样. 由于/usr/share/zoneinfo/Asia/  这个目录下没有北京时区,就选择了上海时区,只要赋值过去就可以了 rm -f /etc/ ...

  4. 多模块后带来的问题解决方法 - OSGI原形(.NET)

    目前只做了基础的功能,比如: 各个模块单独的AppDomain容器 Activator激活 导出的服务检查 不过,虽说这样,但目前的这个版本已经能实现模块分离.互相依赖调用等功能了,对模块划分已经有很 ...

  5. .NET-记一次架构优化实战与方案-梳理篇

    目录 .NET-记一次架构优化实战与方案-梳理篇 .NET-记一次架构优化实战与方案-前端优化 .NET-记一次架构优化实战与方案-底层服务优化 前言 程序员输出是他敲写的代码,那么输入就是他思考好的 ...

  6. C\S 架构 DNS服务器 交换机 路由器

    ------------------------只有不快的斧,没有劈不开的柴;只有想不到的人,没有做不到的事.想干总会有办法,不想干总会有理由!# -------------------------- ...

  7. koa generator

    Koa (koajs) -- 基于 Node.js 平台的下一代 web 开发框架 | Koajs... Koa 框架教程 koa入门 如何评价 Node.js 的koa框架?

  8. 出题人的女装(牛客练习赛38题B) (概率+分式运算)

    链接:https://ac.nowcoder.com/acm/contest/358/B来源:牛客网 出题人的女装 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他 ...

  9. Django lazy load 懒加载 倒序查询

    Django orm默认懒加载   Django orm默认使用的懒加载,即使用的时候才去访问数据库,且每次默认取最少的数据,当然这样有好处也有坏处... 坏处: 会导致频繁的查询数据库,如涉及到外键 ...

  10. Vmware由于centos升级内核不可运行(C header files matching your running kernel were not found)的解决方案

    C header files matching your running kernel were not found. Refer to your distribution's documentati ...