CodeForces 231B Magic, Wizardry and Wonders

B. Magic, Wizardry and Wonders
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.

This morning he has n cards with integers lined up in front of him. Each integer is not less than 1, but not greater than l. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.

Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.

Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than l, the numbers on the appearing cards can be anything, no restrictions are imposed on them.

It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were n cards, they contained integers from 1 to l, and after all magical actions he was left with a single card containing number d.

Help Vasya to recover the initial set of cards with numbers.

Input

The single line contains three space-separated integers: n (2 ≤ n ≤ 100) — the initial number of cards on the table, d (|d| ≤ 104) — the number on the card that was left on the table after all the magical actions, and l (1 ≤ l ≤ 100) — the limits for the initial integers.

Output

If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing n integers from 1 to l. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.

Examples
input
3 3 2
output
2 1 2 
input
5 -4 3
output
-1
input
5 -4 4
output
2 4 1 4 1 

/*  CodeForces 231B
题意: 不好说 举个例子

有一个数列 a[5]
 2 4 1 4 1
然后 a[4] - a[5] = 3; 得到 2 4 1 3
然后 a[3] - a[4] = -2; 得到 2 4 -2
然后 a[2] - a[3] = 6; 得到 2 6
然后 a[1] - a[2] = -4 得到 -4
    就有 -4 这个最终的值 设为d

题目给出 数的个数n  最终值d  然后范围值l (1<=a[i]<=l)
要你随便弄出一个数列出来满足上述条件
不能则输出-1

其实最终值d = a[i]的和(i为奇数) - a[j]的和(j为偶数)
范围就是 a[i] 全为最大值l - b[j]全为最小值1
         a[i] 全为最小值1 - b[j]全为最大值l
如果d在这范围
初始化a[i]全为最大值l   b[j]全为最小值1
    慢慢减减加加就行了
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define pi acos(-1)
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e5 + 5;

int main(void)
{
//	freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin);
    int d, l, n, i, j, dex;
    int a, b, d1, d2, num1[105], num2[105];
    int sum1, sum2;
    cin >> n >> d >> l;
    if (n % 2){
        a = (n+1) / 2;
        b = n - a;
    }
    else a = b = n / 2;
    d1 = l * a - 1 * b;
    d2 = 1 * a - l * b;
    if (d < d2 || d > d1){
        printf("-1\n");
        return 0;
    }
    for (i = 1; i <= a; i++)
        num1[i] = l;
    for (i = 1; i <= b; i++)
        num2[i] = 1;
    dex = 1;
    sum1 = l * a;
    sum2 = 1 * b;
    while (1){
        if (sum1 - sum2 == d)
            break;
        while (num1[dex] == 1) dex++;
        if (dex == a+1) break;
        num1[dex]--;
        sum1--;
    }
    if (dex == a+1){
        dex = 1;
        while (1){
            if (sum1 - sum2 == d)
                break;
            while (num2[dex] == l) dex++;
            num2[dex]++;
            sum2++;
        }
    }
    for (i = 1; i <= b; i++)
        printf("%d %d ", num1[i], num2[i]);
    if (a > b)
        printf("%d", num1[i]);
    printf("\n");

    return 0;
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值