Codeforces Round #377 (Div. 2) 被坑了
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) 被坑了的更多相关文章
- Codeforces Round #377 (Div. 2) D. Exams
Codeforces Round #377 (Div. 2) D. Exams 题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...
- Codeforces Round #377 (Div. 2)
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- Codeforces Round #377 (Div. 2) E. Sockets
http://codeforces.com/contest/732/problem/E 题目说得很清楚,每个电脑去插一个插座,然后要刚好的,电脑的power和sockets的值相同才行. 如果不同,还 ...
- Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟
http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...
- Codeforces Round #377 (Div. 2)A,B,C,D【二分】
PS:这一场真的是上分场,只要手速快就行.然而在自己做的时候不用翻译软件,看题非常吃力非常慢,还有给队友讲D题如何判断的时候又犯了一个毛病,一定要心平气和,比赛也要保证,不要用翻译软件做题: Code ...
- 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 ...
- 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 ...
- Codeforces Round #377 (Div. 2) C. Sanatorium 水题
C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- Win7系统中用anaconda配置tensorflow运行环境
前言:anaconda是一个python Data Science Platform.安装它的契机是因为要用tensorflow. 安装完后感觉用它来管理python运行环境还是挺方便的,常用的con ...
- 每天一个Linux命令:目录
版权声明 更新:2017-04-19博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 在使用Linux的过程中总是发现有一些L ...
- 【LeetCode】064. Minimum Path Sum
题目: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right w ...
- 【LeetCode】046. Permutations
题目: Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] ha ...
- 误删除$ORACLE_HOME/dbs下的参数文件、密码文件,如何快速重建
[oracle@11g dbs]$ pwd/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs[oracle@11g dbs]$ lltotal 24 ...
- 解决CentOS 7安装zabbix 3.0 无法启动zabbix-server的问题[segfault at 18 ip 00007f78842b4bd0 sp 00007fff1995a818 error 4 in libpthread-2.17.so[7f78842ab000+16000]]
解决CentOS 7安装zabbix 3.0 无法启动zabbix-server的问题 [root@localhost sbin]# service zabbix-server start Redir ...
- CHAKRA3 UART2
APP下: 配置BD文件: #define PADS_TCON_CONFIG Unknown_pad_mux #define PADS_UART2_MODE Unknown_pad_mux #defi ...
- python快速上手教程
python版本 python目前的版本分为2.7和3.5,两种版本的代码目前无法兼容,查看python版本号: python --version 基本数据类型 数字类型 整型和浮点型数据和其它编程语 ...
- java的动态代理原理
之前虽然会用JDK的动态代理,但是有些问题却一直没有搞明白.比如说:InvocationHandler的invoke方法是由谁来调用的,代理对象是怎么生成的,直到前几个星期才把这些问题全部搞明白了. ...
- centos7 install pip
1. 安装过程 yum -y install epel-release yum install python-pip pip install --upgrade pip