http://codeforces.com/contest/732/problem/B

题目要求任意两个连续的日子都要 >= k

那么如果a[1] + a[2] < k,就要把a[2]加上数字使得总和 = k,因为这样能传递到a[3]而且是最优的,

a[2]不需要加那么多,只需要加到两个的总和 = k即可,

很坑爹的地方就是 n = 1的时候,其实题目都说了,before the next n days 他们已经走了k

所以n = 1的时候,直接输出0和a[1]即可。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int a[maxn], b[maxn];
void work() {
int n, k;
cin >> n >> k;
for (int i = ; i <= n; ++i) {
cin >> a[i];
b[i] = a[i];
}
if (n == ) {
cout << << endl;
cout << a[] << endl;
return;
}
for (int i = ; i <= n; ++i) {
if (a[i] + a[i - ] < k) {
int add = k - (a[i] + a[i - ]);
a[i] += add;
}
}
int ans = ;
for (int i = ; i <= n; ++i) {
ans += a[i] - b[i];
}
cout << ans << endl;
for (int i = ; i <= n; ++i) {
cout << a[i] << " ";
}
cout << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

Codeforces Round #377 (Div. 2) 被坑了的更多相关文章

  1. Codeforces Round #377 (Div. 2) D. Exams

    Codeforces Round #377 (Div. 2) D. Exams    题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...

  2. Codeforces Round #377 (Div. 2)

    #include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...

  3. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  4. Codeforces Round #377 (Div. 2) E. Sockets

    http://codeforces.com/contest/732/problem/E 题目说得很清楚,每个电脑去插一个插座,然后要刚好的,电脑的power和sockets的值相同才行. 如果不同,还 ...

  5. Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟

    http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...

  6. Codeforces Round #377 (Div. 2)A,B,C,D【二分】

    PS:这一场真的是上分场,只要手速快就行.然而在自己做的时候不用翻译软件,看题非常吃力非常慢,还有给队友讲D题如何判断的时候又犯了一个毛病,一定要心平气和,比赛也要保证,不要用翻译软件做题: Code ...

  7. Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man(贪心)

     传送门 Description Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has ...

  8. Codeforces Round #377 (Div. 2) D. Exams(二分答案)

    D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...

  9. Codeforces Round #377 (Div. 2) C. Sanatorium 水题

    C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. Jmeter-聚合报告

    线程组右键--添加--监听器--聚合报告 Aggreagete Report:jmeter最常用的一个Listener,“聚合报告”. Label:每个jmeter的element(例如HTTP Re ...

  2. Python IOError: [Errno 13] Permission denied:

    一般是代码写错了,比如我遇到的问题就是由于 os.listdir() 传参传错导致的. 本应该传入字符串路径名,但传入了一个文件对象(object)

  3. sangfor-AF 地址转换以及各种模式理解(路由,透明,虚拟网线,混合模式)

    目的地址转换: 1.路由其实很简单的,其实你可以理解为路由器就好了2.透明和虚拟网线的区别:虚拟网线不对数据做任何的处理,你可以理解为不封装不拆包,直接丢给对端.而透明不一样,透明你可以把设备当做是交 ...

  4. python 动态添加属性及方法及“__slots__的作用”

    1.动态添加属性 class Person(object): def __init__(self, newName, newAge): self.name = newName self.age = n ...

  5. Python 2.7数据类型操作_20161010

    为兼容python3.x版本 print 后都加了括号 python 数据类型 参考廖雪峰大神python2.7教程 http://www.liaoxuefeng.com/wiki/001374738 ...

  6. hdu3037Saving Beans——卢卡斯定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3037 卢卡斯定理模板——大组合数的取模 代码如下: #include<iostream> #i ...

  7. 使用XMLConfiguration解析xml,PropertiesConfiguration解析properties等相应信息

    org.apache.commons.configuration.XMLConfiguration; Apache Common-Configuration工具可以从Properties文件,XML文 ...

  8. 关于System类中out属性 实例化的问题

    System类中out属性的声明是这样的: public final static PrintStream out = nullPrintStream(); private static PrintS ...

  9. Ubuntu&nbsp;12.04&nbsp;Eclipse设…

    Ubuntu 12.04 Eclipse设置(黑色背景解决) 分类: ubuntu2012-11-21 10:47 252人阅读 评论(0) 收藏 举报 eclipseEclipseubuntuUbu ...

  10. Centos 6.5 下Nginx安装部署https服务器

    一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩.1.选定源码目录选定目录 /usr/local/cd /usr/local/2.安装PCRE库cd /usr/ ...