【动态规划】codeforces1155D Beautiful Array

D. Beautiful Array
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an array a consisting of n 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 a and multiply all values contained in this subarray by x. You want to maximize the beauty of array after applying at most one such operation.

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

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

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


 最近生活越来越忙碌了。集训队由要组织春训,加上和ZWR,QZZ他们要备战南昌邀请赛,这样的话基本上没有什么周末可言了,不过这或许真是我中意的状态,毕竟畏惧自己懒惰下来。
 这次Edu本来想借机上黄,没想到又崩了。很多人轻松秒掉的D题,居然把我卡掉了。事后被KSJ嘲讽了老久。
 刚看到这题时,因为最大子线段是老题了,就按着老方法做前缀和最小值,然后根据x的值分类讨论,如果x是正数,那么我就求出最大子线段的值乘以x,如果x<=0,那么我先求最小子线段再把区间中每个数乘以x,再求一次最大子线段。后来发现x<=0时我的做法可以有很多反例。然后就开始自闭了。
 我是真心一点都没往dp方面想,看来自己dp的敏感度还不够。其实最大字段和本身也有dp做法,就是 d p [ i ] = m a x ( 0 , a [ i ] + d p [ i − 1 ] ) dp[i]=max(0,a[i]+dp[i-1]) dp[i]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值