CF920D.Tanks
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Petya sometimes has to water his field. To water the field, Petya needs a tank with exactly V ml of water.
Petya has got N tanks, i-th of them initially containing a__i ml of water. The tanks are really large, any of them can contain any amount of water (no matter how large this amount is).
Also Petya has got a scoop that can contain up to K ml of water (initially the scoop is empty). This scoop can be used to get some water from some tank, and after that pour it all into some tank (it is impossible to get water from multiple tanks without pouring it, or leave some water in the scoop when pouring it). When Petya tries to get some water from a tank, he gets min(v, K) water, where v is the current volume of water in the tank.
Is it possible to obtain a tank with exactly V ml of water using these operations? If it is possible, print a sequence of operations that allows to do it. If there are multiple ways to obtain needed amount of water in some tank, print any of them.
佩佳有时需要给他的田地浇水。为了浇灌田地,佩佳需要一个恰好装有 V 毫升水的水箱。
佩佳共有 N 个水箱,其中第 i 个水箱初始时含有 ai 毫升水。这些水箱容量极大,任一水箱均可容纳任意体积的水(无论该体积有多大)。
此外,佩佳还有一个容量至多为 K 毫升的勺子(初始时空置)。该勺子可用于从某个水箱中取水,然后将所取全部水倒入另一个水箱(不允许在未倾倒的情况下从多个水箱取水,也不允许在倾倒时在勺中残留部分水)。当佩佳尝试从某水箱中取水时,他实际取得的水量为 min(v,K),其中 v 是该水箱当前的水量。
能否通过上述操作得到一个恰好装有 V 毫升水的水箱?若可行,请输出实现该目标的一组操作序列;若存在多种方案可使某个水箱中水量恰好为 V,输出任意一种即可。
输入格式
The first line contains 3 integers: N (2 ≤ N ≤ 5000), K (1 ≤ K ≤ 5000), and V (0 ≤ V ≤ 109) — the number of tanks, the maximum volume of water the scoop can contain, and the required amount of water in some tank, respectively.
The second line contains N integers a__i (0 ≤ a__i ≤ 105), where a__i is initial volume of water in i-th tank.
第一行包含 3 个整数:N(2 ≤ N ≤ 5000)、K(1 ≤ K ≤ 5000)和 V(0 ≤ V ≤ 109)——分别表示水箱的数量、舀水工具的最大容量,以及某个水箱中所需的水量。
第二行包含 N 个整数 ai(0 ≤ ai ≤ 105),其中 ai 表示第 i 个水箱的初始水量。
输出格式
If it is impossible to obtain a tank with exactly V ml of water, print NO.
Otherwise print YES in the first line, and beginning from the second line, print the sequence of operations in the following format:
Each line has to contain 3 numbers denoting a compressed operation: "cnt x y" (1 ≤ cnt ≤ 109, 1 ≤ x, y ≤ N), where x is the index of the tank where we get water, y is the index of the tank where we pour water, and cnt is the number of times we transfer water from tank x to tank y.
The number of these lines must not exceed N + 5.
如果无法得到恰好含有 V 毫升水的水箱,则输出 NO。
否则,第一行输出 YES;从第二行开始,按如下格式输出操作序列:
每行包含三个数字,表示一个压缩后的操作:_cnt_ _x_ _y_(其中 1 ≤ _cnt_ ≤ 109,1 ≤ _x, _y_ ≤ N),其中 _x_ 是取水水箱的编号,_y_ 是注水水箱的编号,_cnt_ 表示将水从水箱 _x_ 转移到水箱 _y_ 的次数。
此类行的数量不得超过 N + 5。
输入输出样例
输入#1
2 3 5 2 3
输出#1
YES 1 2 1
输入#2
2 3 4 2 3
输出#2
NO
输入#3
5 2 0 1 3 5 7 9
输出#3
YES 2 2 1 3 3 1 4 4 1 5 5 1
输入解题思路,AI测评打分。不知道怎么写?