博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
guruguru
阅读量:6431 次
发布时间:2019-06-23

本文共 1895 字,大约阅读时间需要 6 分钟。

6576: guruguru

时间限制: 1 Sec  内存限制: 128 MB
提交: 60  解决: 28
[] [] [命题人:]

题目描述

Snuke is buying a lamp. The light of the lamp can be adjusted to m levels of brightness, represented by integers from 1 through m, by the two buttons on the remote control.
The first button is a "forward" button. When this button is pressed, the brightness level is increased by 1, except when the brightness level is m, in which case the brightness level becomes 1.
The second button is a "favorite" button. When this button is pressed, the brightness level becomes the favorite brightness level x, which is set when the lamp is purchased.
Snuke is thinking of setting the favorite brightness level x so that he can efficiently adjust the brightness. He is planning to change the brightness n−1 times. In the i-th change, the brightness level is changed from ai to ai+1. The initial brightness level is a1. Find the number of times Snuke needs to press the buttons when x is set to minimize this number.
Constraints
2≤n,m≤10
5
1≤ai≤m
a
i≠a
i+1
n, m and ai are integers.
 

 

输入

Input is given from Standard Input in the following format:
n m
a1 a2 … an

 

输出

Print the minimum number of times Snuke needs to press the buttons.

 

样例输入

复制样例数据

4 61 5 1 4

样例输出

5
#include 
#include
#include
using namespace std;const int maxn=1e6;typedef long long ll;int n,m;ll p[maxn],psum[maxn],tot,ans;int main() { cin>>n>>m; for(int i=1;i<=n;i++){ scanf("%lld",&p[i]); } for(int i=2;i<=n;i++){ ll l=p[i-1],r=p[i]; if(r
=2){ psum[l+2]+=1,psum[r+1]-=r-(l+2)+1+1,psum[r+2]+=r-(l+2)+1; } } for(int i=1;i<=2*m;i++)psum[i]+=psum[i-1]; for(int i=1;i<=2*m;i++)psum[i]+=psum[i-1]; for(int i=1;i<=m;i++)ans=max(ans,psum[i]+psum[i+m]); cout<
<

 

转载于:https://www.cnblogs.com/czy-power/p/10614402.html

你可能感兴趣的文章
团队作业3——alpha阶段冲刺1
查看>>
JavaScript基础知识五(如何查找上一级作用域)
查看>>
CSS选择器
查看>>
购物车练习
查看>>
js实现在表格中删除和添加一行
查看>>
SOCKET简单爬虫实现代码和使用方法
查看>>
导出excel数字变成科学计数法解决办法
查看>>
跨域解决方案汇总
查看>>
In App Purchase
查看>>
利用PHP实现对于Excel的读取,主要借助于PHPExcel插件来完成
查看>>
python 使用dict和set
查看>>
html介绍
查看>>
Android 资源(resource)学习小结
查看>>
软件测试2019:第四次作业
查看>>
前端网页设计(不忘初心,继续前行,共筑中国梦精美成品)
查看>>
JavaScript面试时候的坑洼沟洄——数据类型
查看>>
android studio如何开启与禁用版本控制vcs
查看>>
购物车的实现(一)——认识Profile
查看>>
C# 通过P/Invoke调用C++函数[DLL]
查看>>
第一个js程序
查看>>