D. Beautiful Array
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array aa consisting of nn integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0.

You may choose at most one consecutive subarray of aa and multiply all values contained in this subarray by xx. You want to maximize the beauty of array after applying at most one such operation.

Input

The first line contains two integers nn and xx (1≤n≤3⋅105,−100≤x≤100) — the length of array aa and the integer xx respectively.

The second line contains nn integers a1,a2,…,an (−109≤ai≤109) — the array aa.

Output

Print one integer — the maximum possible beauty of array aa after multiplying all values belonging to some consecutive subarray x.

Examples
input
5 -2
-3 8 -2 1 -6
output
22
input
12 -3
1 3 3 7 1 3 3 7 1 3 3 7
output
42
input
5 10
-1 -2 -3 -4 -5
output
0
Note

In the first test case we need to multiply the subarray [-2, 1, -6], and the array becomes [-3, 8, 4, -2, 12] with beauty 22([-3, 8, 4, -2, 12]).

In the second test case we don't need to multiply any subarray at all.

In the third test case no matter which subarray we multiply, the beauty of array will be equal to 0.

果然还是太菜了,简单dp都想不出来。

dp[0] 记录不使用x的最大值

dp[1] 记录允许使用x的情况下的最大值

dp[2]记录在前面的区间中已经使用了x的情况下的最大值(尽管可能使用x的区间对最大值并没有贡献)

#include<cstdio>
#include<algorithm>
using namespace std; long long arr[]; int main(){
int n, x;
long long dp[] = {},ans=;
scanf("%d%d",&n,&x);
for(int i=;i<n;i++){
scanf("%I64d",&arr[i]);
dp[] = max(0ll,dp[]+arr[i]);
dp[] = max(dp[],dp[]+arr[i]*x);
dp[] = max(dp[],dp[]+arr[i]);
ans = max(ans,dp[]); }
printf("%I64d\n",ans);
return ; }

Educational Codeforces Round 63 D. Beautiful Array的更多相关文章

  1. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

  2. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  3. Educational Codeforces Round 63部分题解

    Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...

  4. Educational Codeforces Round 63 选做

    D. Beautiful Array 题意 给你一个长度为 \(n\) 的序列.你可以选择至多一个子段,将该子段所有数乘上给定常数 \(x\) .求操作后最大的最大子段和. 题解 考虑最大子段和的子段 ...

  5. Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array (简单DP)

    题目:https://codeforces.com/contest/1155/problem/D 题意:给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和 思路: ...

  6. Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array 分类讨论连续递推dp

    题意:给出一个 数列 和一个x 可以对数列一个连续的部分 每个数乘以x  问该序列可以达到的最大连续序列和是多少 思路: 不是所有区间题目都是线段树!!!!!! 这题其实是一个很简单的dp 使用的是分 ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array(动态规划.递推)

    传送门 题意: 给你一个包含 n 个元素的序列 a[]: 定义序列 a[] 的 beauty 为序列 a[] 的连续区间的加和最大值,如果全为负数,则 beauty = 0: 例如: a[] = {1 ...

  8. Educational Codeforces Round 12 E. Beautiful Subarrays 字典树

    E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...

  9. Educational Codeforces Round 11 A. Co-prime Array 水题

    A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an ...

随机推荐

  1. LINUX升级PHP版本至5.4.26

    参考网址:http://www.itbulu.com/wdcp-php54.html文件:链接:http://pan.baidu.com/s/1slbbNxr 密码:s0yb 1.运行下载PHP版本文 ...

  2. Python %操作符 字符串格式化

    %操作符(字符串格式化,string formatting),说明如下: %[(name)][flags][width].[precision]typecode (name)为命名 flags可以有+ ...

  3. 虚拟机与Linux

    VirtualBox与Ubuntu的下载 对于VirtualBox的下载,网络上的资源非常之多,并且软件也并不是很大,所以并没有耗费很多时间.但是对于Ubuntu的下载来说,一个操作系统,正版的下载肯 ...

  4. 《JAVA程序设计》 20155208 实验四 Android程序设计

    <JAVA程序设计> 20155208 实验四 Android程序设计 实验一: 实验要求: Android Stuidio的安装测试: 参考<Java和Android开发学习指南( ...

  5. 2017-2018-1 20155232 《信息安全系统设计基础》第四周学习总结以及课上myod练习补充博客

    2017-2018-1 20155232 <信息安全系统设计基础>第四周学习总结以及课上myod练习补充博客 课上myod练习 1 参考教材第十章内容 2 用Linux IO相关系统调用编 ...

  6. 20155318 2016-2017-2 《Java程序设计》第四周学习总结

    20155318 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 一.继承 1.父类:为了改进代码,可以将多个代码中相同的部分提升为父类,其他类只需用exte ...

  7. 20155336 2016-2017-2《JAVA程序设计》第二周学习总结

    20155336 2016-2017-2 <JAVA 程序设计>第二周学习总结 教材学习内容 1: GIT版本检测 2: JAVA中基本类型 整数 字节 浮点数 字符 布尔(▲) 通过AP ...

  8. 对PostgreSQL数据库的hstore类型建立GisT索引的实验

    磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页    回到顶级页面:PostgreSQL索引页[作者 高健@博客园  luckyjackgao@g ...

  9. springboot中maven加入本地jar

    一.今天遇到一个问题,在使用springboot打jar的时候出现了本地依赖包打不进去的情况.然后在网上试了很多方式.这里做一个记录 二.加入本地依赖包 <dependency> < ...

  10. springmvc @Valid 接收实体类时出现bean为null的问题

    这是因为传到后端之后,全部以全小写形式处理了 所以前端也需要把name设置为全小写,否则后端不识别,导致接收不到,导致为null