Description
Input
In the only line of input there are two integers n, k (1 ≤ k ≤ n ≤ 500), separated by a space.
Output
Print n integers separated by spaces — the answer for the problem. All the numbers must not be greater than 10 6 by absolute value. It is guaranteed that there exists an optimal solution with numbers up to 10 5by absolute value. If there are multiple possible answers, you may print any of them.
Sample Input
1 1Sample Output
-987654Sample Input
3 2Sample Output
0 7 0
Notes
题解:l,r即为数组元素的位置,都从1开始,给你n,代表有一个1~n的数组,有k个不同的数,然后遍历一遍,使其中任意元素和的种类最少,即存在n-k个0,其他随机选非0数,但要注意两个数互为相反数时求和种类最少。
代码如下:
#include<cstdio>
#include<cmath>
#include<map>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAX = 1e5 + 10;
typedef long long LL;
int a[MAX];
int main()
{
int n,k;
cin>>n>>k;
for(int i=0;i<=n-k;i++)
printf("0 ");
int s=1,qaq=0;
for(int i=n-k+1;i<n;i++)
{
if(i!=n-1)
{
if(qaq==0)
{
qaq=1;
printf("%d ",s);
}
else
{
qaq=0;
printf("%d ",-s);
s++;
}
}
else
if(qaq==0)
{
printf("%d",s);
}
else
{
printf("%d",-s);
}
}
return 0;
}