标签:difficult contains ati multi 接下来 sum array challenge freopen
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:
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.
给定一个整数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;
}
[Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated]-E. Kuroni and the Score Distribution(构造)
标签:difficult contains ati multi 接下来 sum array challenge freopen
原文地址:https://www.cnblogs.com/qieqiemin/p/12410755.html