Codeforces Round #689 (Div. 2, based on Zed Code Competition) E. Water Level 贪心

E. Water Level

In recent years John has very successfully settled at his new job at the office. But John doesn’t like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.

Originally the cooler contained exactly 𝑘 liters of water. John decided that the amount of water must always be at least 𝑙 liters of water but no more than 𝑟 liters. John will stay at the office for exactly 𝑡 days. He knows that each day exactly 𝑥 liters of water will be used by his colleagues. At the beginning of each day he can add exactly 𝑦 liters of water to the cooler, but at any point in time the amount of water in the cooler must be in the range [𝑙,𝑟].

Now John wants to find out whether he will be able to maintain the water level at the necessary level for 𝑡 days. Help him answer this question!

Input

The first line of the input contains six integers 𝑘, 𝑙, 𝑟, 𝑡, 𝑥 and 𝑦 (1≤𝑙≤𝑘≤𝑟≤1018;1≤𝑡≤1018;1≤𝑥≤106;1≤𝑦≤1018) — initial water level, the required range, the number of days, daily water usage and the exact amount of water that can be added, respectively.

Output

Examples

inputCopy

8 1 10 2 6 4

outputCopy

inputCopy

8 1 10 2 6 5

outputCopy

Yes

inputCopy

9 1 10 9 2 9

outputCopy

inputCopy

20 15 25 3 5 7

outputCopy

Yes

Note

In the first example, John can’t increase the amount of water at the beginning of the first day, since it would exceed the limit 𝑟. That is why after the first day the cooler will contain 2 liters of water. The next day John adds 4 liters to the cooler but loses 6 liters, leaving John with 0 liters, which is outside the range [1,10].

In the second example, after the first day John is left with 2 liters of water. At the beginning of the next day he adds 5 liters, then 6 liters get used, leaving John with 1 liter of water which is in range [1,10].

In the third example, after the first day John is left with 7 liters, after the second day — 5 liters, after the fourth — 1 liter. At the beginning of the fifth day John will add 9 liters and lose 2 liters. Meaning, after the fifth day he will have 8 liters left. Then each day the water level will decrease by 2 liters and after the eighth day John will have 2 liters and after the ninth day — 0 liters. 0 is outside range [1,10], so the answer is “No”.

In the fourth example, after the first day John is left with 15 liters of water. At the beginning of the second day he adds 7 liters and loses 5, so after the second day he is left with 17 liters. At the beginning of the third day he adds 7 more liters of water and loses 5, so after the third day he is left with 19 liters. 19 is in range [15,25] so the answer is “Yes”.

有个饮水机,一开始有k升水。

每天早上你可以往里面加y升水,每天晚上你的同事一定会喝掉x升水

问你能否有一种方案使得t天内,水都在[l,r]这个范围。

分成两种情况讨论:

第一种情况 x>=y的时候,当y>=x 即 我每天加的水小于同事喝的水的时候,我贪心使得每天降的尽量少就行。第一天如果k+y

Original: https://www.cnblogs.com/qscqesze/p/14141873.html
Author: qscqesze
Title: Codeforces Round #689 (Div. 2, based on Zed Code Competition) E. Water Level 贪心

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/553170/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 8086汇编 rep 指令

    8086汇编 rep 指令 rep指令常和串传送指令搭配使用功能:根据cx的值,重复执行后面的指令 串传送指令1: movsb 功能:(以字节为单位传送)(1) ((es)×16 …

    技术杂谈 2023年6月1日
    0102
  • mysql 锁

    锁类型 表级锁:开销小,加锁快;不会出现死锁;锁定粒度大,发生锁冲突的概率最高,并发度最低 * 这些存储引擎通过总是一次性同时获取所有需要的锁以及总是按相同的顺序获取表锁来避免死锁…

    技术杂谈 2023年7月25日
    063
  • MySQL的主从复制和分库分表初探

    主从复制 + 分库分表 要讲主从复制,首先来看看MySQL自带的日志文件。 日志 错误日志 错误日志是 MySQL 中最重要的日志之一,它记录了当 mysqld 启动和停止时,以及…

    技术杂谈 2023年6月21日
    0126
  • cuda安装及百度云链接

    1、cuda11.1、11.0、10.2、10.1、10.0、8.0及其相应的cudnn版本 本篇文章是基于移动端1050ti win10安装CUDA 10.0的经验写,由于官网下…

    技术杂谈 2023年7月24日
    075
  • 策略模式、策略模式与Spring的碰撞

    策略模式是GoF23种设计模式中比较简单的了,也是常用的设计模式之一,今天我们就来看看策略模式。 实际案例 我工作第三年的时候,重构旅游路线的机票查询模块,旅游路线分为四种情况: …

    技术杂谈 2023年7月25日
    058
  • html大文件传输问题

    随着视频网站和大数据应用的普及,特别是高清视频和4K视频应用的到来,超大文件上传已经成为了日常的基础应用需求。 但是在很多情况下,平台运营方并没有大文件上传和断点续传的开发经验,往…

    技术杂谈 2023年5月30日
    088
  • 大整数算法

    本文主要整理了几个常用的大整数的算法:大整数加法大整数乘法大整数阶乘大整数幂其实大体的思路都差不多,都是用数组来存储大整数。以下的代码仅仅实现功能,并没有充分详细的参数判断,在实际…

    技术杂谈 2023年6月21日
    077
  • 面向对象的设计模式之SOLID原则

    solid原则包括以下五个: 1、单一职责原则(SRP):表明一个类有且只有一个职责。一个类就像容器一样,它能添加任意数量的属性、方法等。 2、开放封闭原则(OCP):一个类应该对…

    技术杂谈 2023年5月31日
    074
  • 自己动手写线程池——向JDK线程池进发

    自己动手写线程池——向JDK线程池进发 前言 在前面的文章自己动手写乞丐版线程池中,我们写了一个非常简单的线程池实现,这个只是一个非常简单的实现,在本篇文章当中我们将要实现一个和J…

    技术杂谈 2023年7月23日
    084
  • ThreadLocal解决了什么问题

    小明所在的项目组(迭代组:一直在迭代的路上),经常会在已有接口的基础上开发一些小功能,并且前提是在保证现有用户的不受影响基础上迭代。功能迭代,在代码层面小明有1w种实现方法(吹牛的…

    技术杂谈 2023年7月25日
    066
  • 千古前端图文教程-HTML009- HTML5详解2

    HTML5详解2 HTML5详解2 本文主要内容 #拖拽 #1、拖拽元素 2、目标元素 历史 #地理定位 #获取地理信息的方式 #1、IP地址 #2、三维坐标: #3、用户自定义数…

    技术杂谈 2023年7月11日
    093
  • 浅析Vue.use作用、原理和源码解读及为什么建议使用对象plugin.install方式

      const args = toArray(arguments,1)将传入的参数转换成数组, args.unshift(this)再将…

    技术杂谈 2023年5月31日
    085
  • 车牌号正则表达式

    车牌号正则表达式为 测试代码如下 php $reg = "/[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]{1}[A-Z]{1}[A-Z0-9]{…

    技术杂谈 2023年5月31日
    0101
  • 无需编程,基于PostgreSQL零代码生成CRUD增删改查RESTful API接口

    无需编程,基于PostgreSQL零代码生成CRUD增删改查RESTful API接口 回顾 在前面文章中,已经介绍了crudapi主要功能和使用方式,crudapi 1.2.0只…

    技术杂谈 2023年7月25日
    0104
  • iOS-快速开发直播APP所需第三方SDK

    直播SDK 金山云, 推荐七牛云, 推荐阿里云(收费)网易云(收费)腾讯云(收费)又拍云 播放SDK IJKPlayer 自定义IJKPlayer,进度条、音量、亮度 短视频SDK…

    技术杂谈 2023年5月31日
    0118
  • 关于微服务

    原创不易,求分享、求一键三连 微服务会让我们的应用变多,并且为了高可用一个服务会在线上部署多台,那么进行服务调用就存在节点之间的负载均衡和服务发现,负载均衡是为了让各个节点的负载尽…

    技术杂谈 2023年6月1日
    086
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球