CodeForces 1157D N Problems During K Days (构造)

\quad 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 k k days. It means that Polycarp has exactly k k k days for training!

\quad Polycarp doesn’t want to procrastinate, so he wants to solve at least one problem during each of k k k days. He also doesn’t want to overwork, so if he solves x x x problems during some day, he should solve no more than 2 x 2x 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x x x problems during some day, he should solve at least x + 1 x+1 x+1 problem during the next day.

\quad More formally: let [ a 1 , a 2 . . . a k ] \left[ a_{1},a_{2}...a_{k}\right] [a1,a2...ak] be the array of numbers of problems solved by Polycarp. The i − t h i-th ith 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 i ifrom 1 1 1 to k k k should be n n n;
  • a i a_{i} ai should be greater than zero for each i from 1 1 1 to k k k;
  • the condition a i < a i + 1 ≤ 2 a i a_{i}<a_{i+1}\leq2a_{i} ai<ai+12ai should be satisfied for each i from 1 1 1 to k − 1 k−1 k1.
    \quad Your problem is to find any array a a a of length k k k satisfying the conditions above or say that it is impossible to do it.

Input

\quad The first line of the input contains two integers n n n and k k k n ( 1 ≤ n ≤ 1 0 9 , 1 ≤ k ≤ 1 0 5 ) n \left(1≤n≤10^{9}, 1≤k≤10^{5}\right) n(1n109,1k105)— the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.

Output

\quad If it is impossible to find any array a of length k k k satisfying Polycarp’s rules of training, print “NO” in the first line.

\quad Otherwise print “YES” in the first line, then print k k k integers a 1 , a 2 . . . a k a_{1},a_{2}...a_{k} a1,a2...ak in the second line, where ai should be the number of problems Polycarp should solve during the i − t h i-th ith day. If there are multiple answers, you can print any.

Examples

input

26 6

output

YES
1 2 4 5 6 8

input

8 3

output

NO

input

1 1

output

YES
1

input

9 4

output

NO
找到一个长度为 k k k的元素大于0的数组,并且 n ( a i < a i + 1 ≤ 2 a i ) n \left(a_{i}<a_{i+1}\leq2a_{i}\right) n(ai<ai+12ai),整个数组的和等于 n n n
通过手推可以发现其实输出为NO的情况很少,只有 k ∗ ( k + 1 ) 2 > n \frac{k*(k+1)}{2} > n 2k(k+1)>n 或者 n = = 8 n == 8 n==8 && k = = 3 k == 3 k==3 或者 n = = 4 n == 4 n==4 && k = = 2 k == 2 k==2这三种情况,所以可以直接将上述三种情况输出。接下来则是构造如何让 k k k天里做题的数量恰好等于 n n n,由题意易知:每天做题数量至少也要为前一天的数量+1,所以当第一天做题数量 a 1 a_{1} a1确定了,那么总的最少做题数为 k ∗ ( k + 1 ) 2 + ( a 1 − 1 ) ∗ k \frac{k*(k+1)}{2} +(a_{1}-1)*k 2k(k+1)+(a11)k 。所以我们可以通过这个式子算出第一天需要做多少题。让后每天做题都比前一天多做一个即可,多余的题数可以都放在最后一天做。 需要注意的是,当 k = = 1 k==1 k==1或者 k ∗ ( k + 1 ) 2 − 1 = = n \frac{k*(k+1)}{2}-1== n 2k(k+1)1==n 的时候需要特判。

AC代码:

#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n,m) printf("%d %d", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sc(n) scanf("%c",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define mem(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mod(x) ((x)%MOD)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const int maxn = 3e5 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
    int ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')
            sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        ret = ret*10 + ch - '0';
        ch = getchar();
    }
    return ret*sgn;
}
inline void Out(int a)    //Êä³öÍâ¹Ò
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}

int qpow(int m, int k, int mod)
{
    int res = 1, t = m;
    while (k)
    {
        if (k&1)
            res = res * t % mod;
        t = t * t % mod;
        k >>= 1;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    return b==0?a : gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}

int i,j;
ll n, m;
int main()
{
    cin>>n>>m;
    if(m*(m+1)/2>n||(n==8&&m==3)||(n==4&&m==2))
    {
        cout<<"NO"<<endl;
        return 0;
    }
    n-=m*(m+1)/2;
    int base=n/m;
    int cnt=n%m;
    int res=0;
    if(n>1&&(base+m+cnt>2*(base+m-1)))///剩余的全给最后一个
    {
        cnt--;
        res++;
    }
    cout<<"YES"<<endl;
    for(i=1;i<=m;i++)
    {
        if(i!=1)
        {
            cout<<" ";
        }
        if(i==m)
            cout<<base+i+cnt;
        else if(i==m-1)
            cout<<base+i+res;
        else
            cout<<base+i;
    }
    cout<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值