Boxes and Candies
题目描述
Snuke can perform the following operation any number of times:
Choose a box containing at least one candy, and eat one of the candies in the chosen box.
His objective is as follows:
Any two neighboring boxes contain at most x candies in total.
Find the minimum number of operations required to achieve the objective.
Constraints
2≤N≤105
0≤ai≤109
0≤x≤109
输入
N x
a1 a2 … aN
输出
样例输入
Copy
- 3 3
- 2 2 2
样例输出 Copy
- 1
提示
- #pragma GCC optimize(2)
- #include<bits/stdc++.h>
- using namespace std;
- inline int read() {int x=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
- typedef long long ll;
- const int maxn=5e5+;
- const int M=1e7+;
- const int INF=0x3f3f3f3f;
- ll n,x;
- ll a[maxn];
- void inint(){
- cin>>n>>x;
- for(int i=;i<n;i++){
- cin>>a[i];
- }
- }
- int main(){
- inint();
- ll sum=;
- for(int i=;i<n;i++){
- if(a[i]+a[i-]>x){
- if(x-a[i-]>=){
- sum+=a[i]-(x-a[i-]);
- a[i]=(x-a[i-]);
- }
- else{
- sum+=(a[i]+a[i-]-x);
- a[i]=;
- }
- }
- }
- printf("%lld",sum);
- return ;
- }
Boxes and Candies的更多相关文章
- Boxes and Candies(贪心)
Boxes and Candies Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Ther ...
- 2018.09.23 atcoder Boxes and Candies(贪心)
传送门 一道挺有意思的贪心. 从1到n依次满足条件. 注意要特判第一个数已经大于x的情况. 但是如何贪心吃呢? 如果靠左的数没有越界,我们吃靠右的数. 原因是下一次靠右的数就会成为靠左的数,相当于多贡 ...
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...
- Codeforces 488B - Candy Boxes
B. Candy Boxes 题目链接:http://codeforces.com/problemset/problem/488/B time limit per test 1 second memo ...
- Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]
哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058 2014-11-22 06:52:58 njczy2010 B - Ca ...
- Codeforces Round #229 (Div. 2) C
C. Inna and Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #278 (Div. 2)
题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...
- 大数开方 ACM-ICPC 2018 焦作赛区网络预赛 J. Participate in E-sports
Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know ...
- atcoder题目合集(持续更新中)
Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...
随机推荐
- 题解【AcWing91】最短Hamilton路径
题面 看到数据范围这么小,第一眼想到爆搜. 然而这样做的复杂度是 \(\mathcal{O}(n! \times n)\) 的,明显会 TLE. 于是考虑状压 DP. 我们设 \(dp_{i,j}\) ...
- RN开发-Android原生交互
在使用RN开发过程中,难免有些原生功能需要要自己来实现,下面总结一下在使用RN与原生开发交互. 1.在原生代码中定义实现类 1.1 首先继承 ReactContextBaseJaveModule抽象 ...
- flaskapp
前置知识 https://blog.csdn.net/u013457794/article/details/88997699?depth_1-utm_source=distribute.pc_rele ...
- 浅析网页meta标签中X-UA-Compatible属性的使用
今天有一个做开发的朋友突然问你知道很多网站上面加入的X-UA-Compatible属性的意义么?其实这个在以前还专门花了一点时间来验证我自己的想法,结果也确实如自己所预想的那样,八九不离十,当然有一点 ...
- logistic回归损失函数(非常重要,深入理解)
2.2 logistic回归损失函数(非常重要,深入理解) 上一节当中,为了能够训练logistic回归模型的参数w和b,需要定义一个成本函数 使用logistic回归训练的成本函数 为了让模型通过学 ...
- python接口自动化之fiddler使用(二)
1.快捷设置,自定义会话框,查看get和post请求 (1)鼠标放在#后面,右键 (2)选择Customize columns (3)选择Miscellaneous (4)选择RequestMetho ...
- 微信小程序 selectComponent 值为null
这个东西的执行时间感觉有点迷, 我遇到的情况是在page 的onReady onShow 当中 使用 selectComponent 无法获取到子组件的对象 只好退而求其次 在需要触发的方法当中 ...
- [CF]Round514
A Cashier 题意:一个人,一天的工作时长为\(L\),从第\(t_i\)时刻开始有长度为\(l_i\)的工作,他想在工作间隙抽烟,抽一根要\(a\)分钟,问能抽几根. 直接模拟. B Forg ...
- LoadRunner使用记录
基本术语 性能测试--通过自动化的测试工具模拟多种正常.峰值以及异常负载条件来对系统的各项性能指标进行测试. 负载测试和压力测试都属于性能测试,两者可以结合进行. 负载测试,确定在各种工作负载下系统的 ...
- CentOS 7防火墙快速开放端口配置方法
CentOS升级到7之后,发现无法使用iptables控制Linuxs的端口,baidu之后发现Centos 7使用firewalld代替了原来的iptables.下面记录如何使用firewalld开 ...