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. UIWindow 官方文档解析

    UIWindow定义了一个window对象,其用于管理和协调一个app在设备屏幕上的显示.除非一个app能在外部设备上显示内容,一般就只有一个window. window的主要功能:1)提供一个区域来 ...

  2. Ext中 grid 设置行样式

    //设置样式   JS var SetRowClass = function(record, rowIndex, rowParams, store) { if (record.data.status ...

  3. 【php增删改查实例】第二十二节 - 引入百度地图

    20.用户新增地址字段 在实际的开发中,经常会出现对数据表新增或者修改字段的事情,所以,当用户提出加字段的需求时,我们的页面以及后台程序都要进行相应的改动. 本节就以增加一个地址字段为例. 打开nav ...

  4. Spring如何加载log4j配置文件

    今天有朋友在群里问了这个问题,于是写了这篇文章进行整理. 问题如下: 在项目中添加了log4j.properties配置文件,并没有在Spring配置文件中配置,也没有在web.xml中配置,但是代码 ...

  5. Minimal string CodeForces – 797C

    题目链接 题目难度: 1700rating 题目类型:string+贪心+STL 题目思路: 由于题目要求的最终结果是字典序最小的那个字符串,那么我们从贪心的从’a’开始查找字符串里是否存在,如果存在 ...

  6. semantic-ui 标题

    在semantic-ui中定义了5中标题样式,注意HTML中有h1-h6,而semantic-ui中只有h1-h5. 不过需要注意的是,semantic-ui的标题仍旧使用h1-h5来表示,但是在cl ...

  7. 社交CRM SCRM

    社交CRM - 国际版 Binghttps://cn.bing.com/search?FORM=U227DF&PC=U227&q=%E7%A4%BE%E4%BA%A4CRM 社交CRM ...

  8. ansible jenkins war

    Ansible is Simple IT Automationhttps://www.ansible.com/ Ansible中文权威指南- 国内最专业的Ansible中文官方学习手册http://a ...

  9. CMD管道命令使用

    Windows netstat 查看端口.进程占用 开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务 ...

  10. 移动端和PC端页面常用的弹出层

    我们在页面的时候,很多时候用到了弹出层,消息提醒,确认框等等,统一样式的弹出框可以使页面更加优美.在此,我整理一下我们项目的移动端和PC端页面常用的弹出层. 一.移动端 我们需在页面引入弹出框的样式和 ...