D - Different Sums URAL - 2065 (规律)

版权声明: https://blog.csdn.net/nucleare/article/details/89844593

D - Different Sums

 URAL - 2065 

Alex is a very serious mathematician and he likes to solve serious problems. For example, this problem.

You are to construct an array of n integers in which the amount of different integers is not less than k. Among all such arrays you have to construct the one with the minimal amount of different sums on non-empty subarrays. In other words, lets compute the sums of every non-empty subarray and remove repeating sums. You have to minimize the number of remaining sums.

Input

In the only line of input there are two integers nk (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 5 by absolute value. If there are multiple possible answers, you may print any of them.

Example

input output
1 1
-987654
3 2
0 7 0

Notes

Let’s take a closer look on the second sample. We will denote the sum on the segment [ lr] by sumlr) (elements are numbered starting with 1). sum(1, 1) =sum(3, 3) = 0, sum(1, 2) = sum(1, 3) = sum(2, 2) = sum(2, 3) = 7, so there are only two different sums.

思路:递增的正负正负就能相互抵消了

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <functional>
#include <cstdio>
#include <cmath>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
#define ll long long
#define F first
#define S second
#define p_b push_back
#define m_p make_pair
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int M = 1e7 + 7;
const int N = 1e6 + 7;
int main() {
	
	int n, k;
	scanf ("%d %d", &n, &k);
	printf ("0");
	int j = 1;
	for (int i = 1; i < k; ++i) {
		if (i&1) printf (" %d", j);
		else printf (" %d", -j);
		if (i%2 == 0) ++j;
	}
	for (int i = 1; i < (n - (k - 1)); ++i) {
		printf (" 0\n");
	}
	puts("");
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/nucleare/article/details/89844593