CF1157D.N Problems During K Days
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a1,a2,…,ak] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
- sum of all ai for i from 1 to k should be n;
- ai should be greater than zero for each i from 1 to k;
- the condition ai<ai+1≤2ai should be satisfied for each i from 1 to k−1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Polycarp 需要在一场重要的编程竞赛前恰好解决 n 道题目,以提升自己的编程能力。而这场竞赛很快就要举行,确切地说,将在 k 天后开始。这意味着 Polycarp 恰好有 k 天时间进行训练!
Polycarp 不想拖延,因此他希望在 k 天中的每一天至少解决一道题。他也不想过度劳累,因此若某天他解决了 x 道题,则下一天解决的题目数量不能超过 2x 道。最后,为了切实提升能力,若某天他解决了 x 道题,则下一天解决的题目数量至少应为 x+1 道。
更形式化地:设 [a1,a2,…,ak] 为 Polycarp 每天所解题数构成的数组,其中第 i 个元素 ai 表示他在训练第 i 天所解决的题目数量。则该数组必须满足以下条件:
- 所有 ai(其中 i 从 1 到 k)之和应等于 n;
- 对每个 i(从 1 到 k),ai>0;
- 对每个 i(从 1 到 k−1),需满足条件 ai<ai+1≤2ai。
你的任务是:找出任意一个长度为 k 的满足上述条件的数组 a;若不存在这样的数组,则判定其不可能。
输入格式
The first line of the input contains two integers n and k (1≤n≤109,1≤k≤105) — the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
输入的第一行包含两个整数 n 和 k(1≤n≤109,1≤k≤105)—— 分别表示 Polycarp 想要解决的问题数量以及他想要训练的天数。
输出格式
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a1,a2,…,ak in the second line, where ai should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
如果无法找到满足 Polycarp 训练规则的长度为 k 的数组 a,则在第一行输出 "NO"。
否则,在第一行输出 "YES",在第二行输出 k 个整数 a1,a2,…,ak,其中 ai 表示 Polycarp 在第 i 天应解决的问题数量。若存在多个答案,输出任意一个即可。
输入输出样例
输入#1
26 6
输出#1
YES 1 2 4 5 6 8
输入#2
8 3
输出#2
NO
输入#3
1 1
输出#3
YES 1
输入#4
9 4
输出#4
NO
输入解题思路,AI测评打分。不知道怎么写?