#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, x;
const int N = 5010;
int a[N];
int maxseg[N]; // maxseg[i]表示长度为`i`的序列的最大和
int main() {
int tc;cin >> tc;while (tc--) {
cin >> n >> x;for (int i = 0; i < n; ++i) cin >> a[i];maxseg[0] = 0;for (int i = 1; i <= n; ++i) maxseg[i] = -INF;// Iterate over length `l`, find the max value within the segmentfor (int l = 0; l < n; ++l) {
int sum = 0;for (int r = l; r < n; ++r) {
sum += a[r];maxseg[r - l + 1] = max(maxseg[r - l + 1], sum);}}// If we want to increase `k` numbers, it optimal to increase number within// the segment if possible, i.e, if(len <= k), the sum will be increased by// k*x; else, the sum will be increased by len*x//// So the problem is effectively turned into a problem to find the maximal// sum of subsequence of length ranging from 1 to nfor (int k = 0; k <= n; ++k) {
int best = 0;for (int len = 0; len <= n; ++len)best = max(best, maxseg[len] + min(k, len) * x);cout << best << ' ';}cout << endl;}
}
详细解决方案
Codeforces Educational Round 123 C Increase Subarray Sums
热度:39 发布时间:2023-12-05 08:28:28.0
相关解决方案
- 为什么输入0.705四舍五入(System.Math.Round)后得到的结果是0.70 ?该如何处理
- excel四舍五入的有关问题:round(0.265,2)=0.27,round((1605.3-1600)*0.05,2)=0.26,请
- 【剁手】CodeForce Round 168 Div B1(熬夜就水出来一个小弟我操)
- Codeforces Round #166 (Div. 二) D - Good Substrings
- Codeforces Round #165 (Div. 二)(完全)
- Codeforces Round #166 (Div. 二)
- Codeforces Round #167 (Div. 二 && Div.1)
- Draw rect and round with google 地图
- Javascript Math ceil()、floor()、round()三个函数的差异
- how to increase heap size?解决方法
- SELECT ROUND (0.6,0)解决办法
- round 的返回值的有关问题
- iPhone Core Quartz 一- Round Rectangle
- Round Rect Button 爲什麽不能設置 Set to Back,该如何解决
- 求高手解决,v地图 allocation for size 8192 failed: use vmalloc=<size> to increase size
- Codeforces Round #282 (Div. 二)-A. Digital Counter
- Codeforces Round #248 (Div. 一)——Nanami's Digital Board
- Codeforces 10C Digital Root 法令题
- Tutorial CodeForces Round 289 (Div.2) (Second Winter Computer Camp Selection 2015) 例题
- codeforces 492D Vanya and Computer Game(额。数学题?水题吧)
- codeforces #199 C. Cupboard and Balloons 例题
- Codeforces Round #199 (Div. 二) C. Cupboard and Balloons
- Codeforces Round #199 (Div. 二) C. Cupboard and Balloons
- Round-tripping Blob to Array为数组值增加了48
- Educational Codeforces Round 77 C. Infinite Fence
- codeforces 1272B Snow Walking Robot
- 理解flume hdfs sink round 和roll
- es max virtual memory areas vm.max_map_count [65530] is too low, increase to at least 262144
- cigarettesTriangular Sums
- Codeforces Round #380 C. Road to Cinema .