CF1200B
CF1200B
解法:
贪心。当在第i列时,尽可能多的取走第i列的木块使得袋子里的木块尽可能多
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e3 + 5;
int n,m,k,T,h[N];
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d%d%d",&n,&m,&k);
for(int i = 1 ; i <= n ; i++)
scanf("%d",&h[i]);
if (n == 1) {
puts("YES");
continue;
}
int pos = 1;
for(int i = 2 ; i <= n ; i++) {
if(h[pos] > h[i]) {
int t = h[pos] - h[i] + k;
if (t > h[pos])
t = h[pos];
m += t;
pos++;
} else if (h[i] - h[pos] <= k) {
int t = k - h[i] + h[pos];
if (t > h[pos])
t = h[pos];
m += t;
pos++;
} else if (h[i] - h[pos] <= k + m) {
m -= h[i] - h[pos] - k;
pos++;
} else {
puts("NO");
break;
}
}
if (pos == n) puts("YES");
}
//system("pause");
return 0;
}
CF1200B的更多相关文章
随机推荐
- ant Windows下环境变量配置 安装 编译
下载 官网:[http://ant.apache.org/] 其他版本:[http://archive.apache.org/dist/ant/binaries/] 点击这个进入下载页面 Window ...
- Kong命令(二)service
service介绍: service 是声明了一组name.host.port.protocol等配置的函数.可以绑定route.upstream上下游服务.并且对于route.upstream可以绑 ...
- 关于linux中关在共享文件的NFS 提示错误解决办法
0. 查看挂载情况命令 : findmnt 1. 如果在客户机上遇到如下这样的提示错误,有可能的原因是因为没有安装nfs-utils 只需要yum install nfs-utils 就解决了 ...
- js写guess网页
(一)布局 猜前 -> 猜后 (二)明确实现功能和具体实现: 1.网页生 ...
- redis集群1
redis-trib.rb命令详解 redis-trib.rb是官方提供的Redis Cluster的管理工具,无需额外下载,默认位于源码包的src目录下,但因该工具是用ruby开发的,所以需要准 ...
- nc 命令
目录 nc 命令 一.简介 二.案例 1.端口扫描 2.聊天 3.文件传输 4.目录传输 5.加密网络发送的数据 6.流视频 7.克隆一个设备 8.打开一个shell 9.反向shell 10.指定端 ...
- 《数据结构与算法之美》 <05>链表(下):如何轻松写出正确的链表代码?
想要写好链表代码并不是容易的事儿,尤其是那些复杂的链表操作,比如链表反转.有序链表合并等,写的时候非常容易出错.从我上百场面试的经验来看,能把“链表反转”这几行代码写对的人不足 10%. 为什么链表代 ...
- httpd-2.4源码编译
APR APR(Apache portable Run-time libraries,Apache可移植运行库) 主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库.在早 ...
- linux基础6-bash shell编程
1. type [-ta] name 一般情况下,type命令被用于判断另外一个命令是否是内置命令,但是它实际上有更多的用法. 1.1.判断一个名字当前是否是alias.keyword.functio ...
- centos7防火墙相关
selinux(保护文件安全) 安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统. SE ...