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. DataHub使用小结(一)——概述

    一.概念 1.什么是DataHub DataHub是流式数据(Streaming Data)的处理平台,提供对流式数据的发布(Publish),订阅(Subscribe)和分发功能, 可以轻松构建基于 ...

  2. System.IO.Pipelines: .NET高性能IO

    System.IO.Pipelines是一个新的库,旨在简化在.NET中执行高性能IO的过程.它是一个依赖.NET Standard的库,适用于所有.NET实现. Pipelines诞生于.NET C ...

  3. RabbitMQ 惰性队列Lazy Queue

    RabbitMQ 队列分为几种类型,按照不同维度来分,可以分为排他性队列.普通队列.延迟队列.惰性队列.发布订阅队列等. 今天我们讨论的主角是惰性队列 Lazy Queue.众所周知,队列可以存储消息 ...

  4. Centos7 ssh配置RSA证书登录

    修改sshd配置文件 vim /etc/ssh/sshd_config #增加以下三项 RSAAuthentication yes PubkeyAuthentication yes Authorize ...

  5. Full Regularization Path for Sparse Principal Component Analysis

    目录 背景 Notation Sparse PCA Semidefinite Relaxation Low Rank Optimization Sorting and Thresholding 背景 ...

  6. A. Chess Placing

    链接 [https://codeforces.com/contest/985/problem/A] 题意 给你一个偶数n,输入n/2个数,代表棋子的位置,有一个1*n的棋盘是黑白相间的 问你使得所有棋 ...

  7. [2017BUAA软工助教]团队开发阶段CheckList

    alpha阶段流程与相关节点 以下流程与团队项目中个人的得分点是一一对应的,详见QA文档中"个人在团队项目的得分部分" http://www.cnblogs.com/Childis ...

  8. tomcat启动参数

    /usr/java/jdk1..0_191-amd64/bin/java -Djava.util.logging.config./conf/logging.properties -Djava.util ...

  9. Yii2几个要注意的小地方

    本人新手, 刚接触Yii, 记录下遇到的坑, 大神请绕道/ 1. //插入数据到数据库, 需要 new 一下,设置属性: $info = new BasicInfo(); $info -> se ...

  10. POI解析Excel代码

    // 批量区域数据导入 @Action(value = "area_batchImport") public String batchImport() throws IOExcep ...