<span>[Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated]-E. Kuroni and the Score Distribution(构造)</span>

[Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated]-E. Kuroni and the Score Distribution(构造)

Kuroni is the coordinator of the next Mathforces round written by the "Proof by AC" team. All the preparation has been done, and he is discussing with the team about the score distribution for the round.

The round consists of nn problems, numbered from 11 to nn. The problems are ordered in increasing order of difficulty, no two problems have the same difficulty. A score distribution for the round can be denoted by an array a1,a2,…,ana1,a2,…,an, where aiai is the score of ii-th problem.

Kuroni thinks that the score distribution should satisfy the following requirements:

  • The score of each problem should be a positive integer not exceeding 109109.
  • A harder problem should grant a strictly higher score than an easier problem. In other words, 1≤a1<a2<⋯<an≤1091≤a1<a2<⋯<an≤109.
  • The balance of the score distribution, defined as the number of triples (i,j,k)(i,j,k) such that 1≤i<j<k≤n1≤i<j<k≤n and ai+aj=akai+aj=ak, should be exactly mm.

Help the team find a score distribution that satisfies Kuroni's requirement. In case such a score distribution does not exist, output −1−1.

Input

The first and single line contains two integers nn and mm (1≤n≤50001≤n≤5000, 0≤m≤1090≤m≤109) — the number of problems and the required balance.

Output

If there is no solution, print a single integer −1−1.

Otherwise, print a line containing nn integers a1,a2,…,ana1,a2,…,an, representing a score distribution that satisfies all the requirements. If there are multiple answers, print any of them.

Examples

input

Copy

5 3

output

Copy

4 5 9 13 18

input

Copy

8 0

output

Copy

10 11 12 13 14 15 16 17

input

Copy

4 10

output

Copy

-1

Note

In the first example, there are 33 triples (i,j,k)(i,j,k) that contribute to the balance of the score distribution.

  • (1,2,3)(1,2,3)
  • (1,3,4)(1,3,4)
  • (2,4,5)(2,4,5)

题意:

给定一个整数n,以及一个整数m,

让你构造出一个含有n个整数的数组a,使其满足\(a_i + a_j = a_k\)的点对\((i, j, k)\)个数为m个。

思路:

对于数组中的第k个数\(a_k\)无论设为何值,满足\(a_i + a_j = a_k\)的点对\((i, j, k)\)个数最多为\(\lfloor \frac{k-1}{2} \rfloor\)

先设\(N= \lfloor \frac{0}{2} \rfloor + \lfloor \frac{1}{2} \rfloor + \dots + \lfloor \frac{n-1}{2} \rfloor\),如果\(m>N\)那么答案为-1。

再考虑答案存在的情况,

我们需要找到一个下标\(k\),使其满足\(\sum_{i = 1}^k \lfloor \frac{i-1}{2} \rfloor \le m < \sum_{i = 1}^{k+1} \lfloor \frac{i-1}{2} \rfloor\)

对于\(1 \leq i \leq k\)\(a_i=i\),此时我们满足条件的点对还差\(cha=m-\sum_{i = 1}^k \lfloor \frac{i-1}{2} \rfloor\)个,

只需要让\(a_{k+1}=(a[k] + a[k+1 - cha * 2])\) 就恰好有了m个点对。

接下来考虑\(k+1<i \leq n\)\(a_i\)该填什么数呢?

因为点对我们已经满足了,我们只需要让新填的数不新增出合法点对,且要符合范围(不超过\(10^9\))。

一个简单的构造方法为:\(a_i=a_{i-1}+k+1, (k+1<i \leq n)\)

\(x=k+1\),那么这样构造后面的\(a_i=a_{k+1}+x,a_i=a_{k+1}+2x,a_i=a_{k+1}+3x \dots\)

因为数组中没出现\(x\),所以不会有新增的合法点对。

代码:


/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
ll k;
int a[maxn];
ll b[maxn];
void out()
{
    repd(i, 1, n)
    {
        printf("%d%c", a[i], i == n ? '\n' : ' ');
    }
}
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    n = readint();
    k = readll();
    repd(i, 1, n)
    {
        a[i] = i;
        b[i] = (i - 1) / 2;
    }
    ll now = 0ll;
    int flag = 0;
    repd(i, 3, n)
    {
        if (now == k)
        {
            flag = i - 1;
            break;
        }
        if (now + b[i] > k)
        {
            int cha = k - now;
            a[i] = (a[i - 1] + a[i - cha * 2]);
            flag = i;
            break;
        } else
        {
            now += b[i];
        }
    }
    if (!flag)
    {
        if (now == k)
        {
            out();
        } else
        {
            printf("-1\n");
        }
    } else
    {
        int x = flag + 1;
        repd(i, flag + 1, n)
        {
            a[i] = a[i - 1] + x;
        }
        out();
    }
    return 0;
}



全部评论

相关推荐

01-30 16:13
浙江大学 Java
点赞 评论 收藏
分享
时间线:&nbsp;1.4-1.5:&nbsp;boss&nbsp;牛客&nbsp;官网&nbsp;实习僧海投了两天,&nbsp;感觉确实没啥招人的啊,&nbsp;心里凉了一半.1.6:&nbsp;中午快手约面,&nbsp;下午字节hr飞书私聊约面,&nbsp;当时想着第一次面大厂感觉三个过一个一面就已经赢了.1.7:&nbsp;下午&nbsp;3点大厂处女面,&nbsp;哈哈面试官是重邮红岩的直接保送;&nbsp;5点快手一面,&nbsp;我说这个是我的第二次大厂面试,&nbsp;面试官问要是拿到字节和快手选择哪个,&nbsp;我说昨天看了一晚上快手百分百选快手哈哈哈.&nbsp;晚上5.30字节约二面,&nbsp;快手约二面,&nbsp;小红书约一面.1.8:&nbsp;下午2点快手二面,&nbsp;聊天面体验非常好(当天电话确认入职时间);&nbsp;4点字节二面这次不是校友了,&nbsp;然后有一个CSS实现switch效果的忘记属性咋写了,&nbsp;感觉危了;&nbsp;7.30&nbsp;问字节hr是不是挂了;&nbsp;9点开始小红书一面,&nbsp;难死我了,&nbsp;但我还是笑着面完了,&nbsp;然后卸载了小红书,&nbsp;但是过了一会会小红书hr约二面,&nbsp;遂下回来了字节约三面.1.9:&nbsp;下午2点字节三面,&nbsp;依旧聊天+算法,&nbsp;自己太菜了有一个写错了,&nbsp;面完感觉又危了;&nbsp;5点面小红书20min结束(offer审批);5.30又去问字节hr是不是挂了,&nbsp;hr小姐姐说干嘛用一个句式,&nbsp;我说手写题又又又没写出来😂,&nbsp;2min后约hr面;8.30&nbsp;快手offer总结,&nbsp;自己运气好遇到了好公司好部门好面试官,&nbsp;字节剪映&nbsp;快手电商&nbsp;小红书支付的面试体验都非常好,&nbsp;不会的题会带你一步一步思考,&nbsp;流程也非常快全部都是当天推进,&nbsp;小红书是以分钟为单位推进.&nbsp;&nbsp;面经以及细节等我慢慢整理,&nbsp;&nbsp;以及保佑所有的审批不要出问题,&nbsp;我是真怕最后全过了0offer😂bg:&nbsp;重邮&nbsp;大数据&nbsp;蓝山工作室&nbsp;一段非大厂实习
独角仙梦境:这是真👻了
找实习记录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务