CF287B.Pipeline
普及+/提高
通过率:0%
时间限制:0.40s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.
A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe.
The figure shows a 4-output splitter
Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.
Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.
沃瓦,终极图勒的新萨满,想要建造一条供水管道。由于终极图勒恰好有 n 座房屋,沃瓦希望该城市恰好拥有 n 根管道,且每根管道都必须连接至供水系统。当一根管道中有水流流出时,它即可被连接至供水系统。初始时,沃瓦仅有一根带有水流的管道。此外,沃瓦还拥有一些分流器(splitters)。
一个分流器是一种装置,包含一个输入端口(可连接至供水管道)和 x 个输出端口。当分流器连接至一根供水管道时,水将从每个输出端口流出。你可以将这些输出端口视为普通管道:例如,若某输出端口有水流流出,则它本身也可被连接至供水系统。任意一根供水管道最多只能连接一个分流器。
图中展示了一个具有 4 个输出端口的分流器
沃瓦拥有每种类型各一个分流器:即分别具有 2,3,4,…,k 个输出端口的分流器。请帮助沃瓦使用最少数量的分流器来建成所需管道;若不可能实现,请予以说明。
沃瓦需要最终管道系统中恰好有 n 根管道能向外流水。注意:这些管道中的一部分可以是分流器的输出端口。
输入格式
The first line contains two space-separated integers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 109).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
第一行包含两个以空格分隔的整数 n 和 k(1 ≤ n ≤ 1018,2 ≤ k ≤ 109)。
请注意,在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流或 %I64d 说明符。
输出格式
Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.
输出一个整数——构建该管道所需的最小分流器数量。如果无法用给定的分流器构建管道,则输出 -1。
输入输出样例
输入#1
4 3
输出#1
2
输入#2
5 5
输出#2
1
输入#3
8 4
输出#3
-1
输入解题思路,AI测评打分。不知道怎么写?