传送

时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format:%lld

题目描述

Today HH finds a non-decreasing sequence(a1,a2…an,ai≤ai+1), he
thinks it’s not beautiful so he wants to make it beautiful. To make
it, HH will choose exactly one number and move it forward at least k
steps(i.e. you can move ai to aj if k≤i−j), and then he defines the
beautiful value F(n) as HH asks you to calculate max(F(n))

输入描述:

The first line contains an positive integer T(1≤T≤10), represents
there are T test cases. For each test case: The first line
contains two positive integers n,k(1≤n≤105,1≤k<n),the length of the
sequence ,the least steps you need to move. The second line contains
n integers a1,a2…an(1≤ai≤108) - the sequence.

输出描述:

For each test case, you should output the max F(n).

示例1
输入

3
5 3
1 1 3 4 5
5 2
1 1 3 4 5
5 1
1 1 3 4 5

输出

46
50
53

说明

In the first example, you can move the fifth number 4 for 3 steps and
make the sequence become [4,1,1,3,5], then the beautiful value is
4×1+1×2+1×3+3×4+5×5=46. You can also move the fifth number to make it
become [1,5,1,3,4], the beautiful value is also 46. In the second
example, you can move the fifth number 5 for 2 steps and make the
sequence become [1,1,5,3,4] In the second example, you can move the
second number 1 for 1 steps and then the sequence is still [1,1,3,4,5]

备注:

scanf is commended。

题解:
比如:A B C D E
对应:1 2 3 4 5
此时的值为ans1=1A+2B+3C+4D+5E
现在D移动到B前面,移动了两步
A D B C E
此时的值:ans2 = 1
A+2D+3B+4C+5E
=1A+2B+3C+4D+5E-3D+(B+C+D)
观察ans1与ans2相比有什么变化
发生改变就是减去这个数字的k倍,再加上被移动数字(共k个)的和
因为D向前移动k,说明Di–>D(i-k)
BC因为D向前而被拱到后面,从Bi—>b(i+1)
被移动数字之和我们可以用前缀和pre实现
看代码:

#include<bits/stdc++.h>
#define for(w) for(int i=w;i<=n;i++)
using namespace std;
const int maxn=1e5+3;
long long int sum[maxn],pre[maxn];
long long int a[maxn];
long long tot=0,ans=0;
int main()
{long long t,n,k;//cin>>t;scanf("%lld",&t);while(t--){tot=0;ans=0;memset(pre,0,sizeof(pre));scanf("%lld%lld",&n,&k);for(1){//   cin>>a[i];scanf("%lld",&a[i]);ans=ans+a[i]*i;}for(1){pre[i]=pre[i-1]+a[i];}for((k+1)){tot=max(tot,ans-a[i]*k+(pre[i-1]-pre[i-k-1]));}cout<<tot<<endl;}
}

Maximize The Beautiful Value相关推荐

  1. Maximize The Beautiful Value (前缀和贪心)

    Maximize The Beautiful Value (前缀和&贪心) 题目传送门 题意:给定长度为n不递减序列,求操作一次使其F[n]最大. #include<bits/stdc+ ...

  2. 21天好习惯第一期-3

    牛客算法周周练1 [题解] 牛客算法周周练1 [题解] 小结: 这个比赛最有意思了,对小白来说很友好,都是一些基础的算法,第一题就是我在学习前缀和的时候写过的,当时非常高兴直接秒提交了,E题打表简直不 ...

  3. C. Beautiful Regional Contest

    链接:https://codeforces.com/contest/1265/problem/C So the Beautiful Regional Contest (BeRC) has come t ...

  4. 【CodeForces 1265C --- Beautiful Regional Contest】

    [CodeForces 1265C --- Beautiful Regional Contest] 题目来源:点击进入[CodeForces 1265C - Beautiful Regional Co ...

  5. Python Beautiful Soup类的基本元素

    Beautiful Soup库是解析,遍历,维护"标签树"的功能库. 条件: pip install lxml pip install html5lib 以下5种基本元素是使用方法 ...

  6. Python爬虫利器之Beautiful Soup的全世界最强用法 五百行文章!

    0. 前言 爬虫是一个非常有意思的东西,比如自己做的一个网页上面什么数据都没有就可以爬虫别人的 然后进行去重 数据分析等等 在这里因为爬虫涉及到的方面非常多 1. Beautiful Soup的简介 ...

  7. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  8. CodeForces - 55D Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D 题意:求区间[L,R]有多少个Beautiful numbers.Beautiful number ...

  9. 第十四届华中科技大学程序设计竞赛 B Beautiful Trees Cutting【组合数学/费马小定理求逆元/快速幂】...

    链接:https://www.nowcoder.com/acm/contest/106/B 来源:牛客网题目描述 It's universally acknowledged that there're ...

最新文章

  1. oracle 表查看依赖,oracle – 表依赖的递归查询不会像我想的那样递归
  2. POJ 2728 01分数规划
  3. jstack可以定位到线程堆栈
  4. python习题:修改文件里的内容
  5. AI基础:正则表达式
  6. CF757F-Team Rocket Rises Again【最短路,DAG支配树】
  7. jq的插件 vue中引用_详解如何在 vue 项目里正确地引用 jquery 和 jquery-ui的插件
  8. 计算机二级考试c语言公共基础知识,全国计算机二级c语言公共基础知识考试内容.doc...
  9. sql数据库备份默认路径_在Linux上SQL Server中更改默认数据库文件和备份路径
  10. 米线店结账程序 装饰着模式_云南大学《设计模式》实验报告2_装饰者模式.doc...
  11. 表上作业法求解运输问题----python生成初始解
  12. Mi11Pro刷机记录
  13. ORACLE动态SQL语句
  14. 二元函数的洛必达法则
  15. 06-适配器模式Quarkus实现
  16. 无人值守地磅称重系统方案的设计原理
  17. java if(true)_使用 if(true) 和 if(false)
  18. 【高数】用拉格朗日中值定理解决极限问题
  19. 记录 —— lammps
  20. Java基础短时自学总结

热门文章

  1. 凭自己本事单的身是一种怎样的体验?你根本配不上如此优秀的我!
  2. docker 查看容器_Docker介绍
  3. linux docker导入镜像,Docker镜像的导入和导出
  4. linux服务器管理公司用户,在Linux服务器Jenkins中管理用户和角色的方法
  5. 修改图层的范围_【PS|第39期】数字绘画 使用填充图层
  6. 通过图书编号查询python_文字版图书管理-python练习
  7. python数据分析与展示 pdf课件_python数据分析与展示 课件 相关实例(示例源码)下载 - 好例子网...
  8. 西北工业大学计算机毕业论文,光纤通信发射机本科毕业论文 西北工业大学.docx...
  9. java编程_Java编程和C语言的比较
  10. 算法题目——被围绕的区域(dfs,bfs)