ICPC Asia Taipei-Hsinchu Regional 2019 The League of Sequence Designers(构造)

Problem Description

Consider the following sequence problem: given nn integers a_{1}, a_{2}, \ldots, a_{n},a1​,a2​,…,an​, where \left|a_{i}\right| \leq 10^{6}∣ai​∣≤106for all 1 \leq i \leq n1≤i≤n and 1 \leq n<2000,1≤n<2000,compute

 

\max _{1 \leq \ell \leq r \leq n}(r-\ell+1) \cdot \sum_{\ell \leq i \leq r} a_{i}max1≤ℓ≤r≤n​(r−ℓ+1)⋅∑ℓ≤i≤r​ai​

 

As an attempt to solve the above problem, Natasha came up with a textbook greedy algorithm using the idea of computing heaviest segment via prefix sums as follows:

As you can see, Natasha's idea is not entirely correct. For example, when the input sequence is 6,-8,7,-42,6,−8,7,−42, the function FindAnswer will return 7,7, but the correct answer is 3 \cdot(6-8+7)=153⋅(6−8+7)=15

Bruce tries to tell Natasha that her solution is not correct, but she does not believe.

Given an integer kk and a lower bound of sequence length LL, your task in this problem is to help Bruce design a sequence of nn integers with n \geq Ln≥L such that the correct answer and the answer produced by Natasha's algorithm differ by exactly kk

Note that, the sequence you produce must follow the specification to the original problem. That is, 1 \leq n<20001≤n<2000 and \left|a_{i}\right| \leq 10^{6}∣ai​∣≤106 for all 1 \leq i \leq n .1≤i≤n. Print -1−1 if it is impossible to form such a sequence.

Input Format

The input file starts with an integer TT, the number of testcases, in the first line.

Then there are TT lines, one for each testcase, each containing two integers kk and LL, separated by a space.

Output Format

The output for each testcase consists of either one or two lines, depending on the result. The format is as follows.

If there exists no such sequences, print the integer -1−1 in a line. Otherwise, print in the first line the integer nn denoting the length of the sequence. In the second line, print the nnintegers a_{1}, \ldots, a_{n}a1​,…,an​ separated with a space.

Technical Specification

  • 1 \leq T \leq 51≤T≤5
  • 1 \leq k \leq 10^{9}1≤k≤109
  • 0 \leq L \leq 10^{9}0≤L≤109

本题答案不唯一,符合要求的答案均正确

样例输入复制

3
8 3
612 7
4 2019

样例输出复制

4
6 -8 7 -42
7
30 -12 -99 123 -2 245  -300
-1

题意:

构造一个数列,使得给出的程序返回的结果与正确结果正好相差 k 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int N = 2e3 + 10;

int a[N];

int main()
{
    int k, l, t;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d", &k, &l);
        if(l >= 2000)
        {
            cout<<-1<<'\n';
            continue;
        }
        int n = 1999;
        a[1] = -1;
        int tmp = 1999 + k;
        for(int i = 2; i < n; ++i)
        {
            a[i] = tmp / 1998;    //匀开
        }
        a[n] = tmp % 1998 + tmp / 1998;
        cout<<n<<'\n';
        for(int i = 1; i <= n; ++i)
        {
            cout<<a[i];
            if(i < n)
                cout<<'\n';
        }
    }
    return 0;
}

 

全部评论

相关推荐

02-22 20:28
重庆大学 Java
程序员牛肉:首先不要焦虑,你肯定是有希望的。 首先我觉得你得好好想一想自己想要什么。找不到开发岗就一定是失败的吗?那开发岗的35岁危机怎么说?因此无论是找工作还是考公我觉得你都需要慎重的想一想。但你一定要避开这样一个误区:“我是因为找不到工作所以不得不选择考公”。 千万不要这么想。你这个学历挺好的了,因此你投后端岗肯定是有面试机会的。有多少人简历写的再牛逼,直接连机筛简历都过不去有啥用?因此你先保持自信一点。 以你现在的水平的话,其实如果想要找到暑期实习就两个月:一个月做项目+深挖,并且不断的背八股。只要自己辛苦一点,五月份之前肯定是可以找到暑期实习的,你有点太过于高看大家之间的技术差距了。不要焦虑不要焦虑。 除此之外说回你这个简历内容的话,基本可以全丢了。如果想做后端,先踏踏实实做两个项目再说+背八股再说。如果想考公,那就直接备战考公。 但是但是就像我前面说的:你考公的理由可以是因为想追求稳定,想追求轻松。但唯独不能是因为觉得自己找不到工作。不能这么小瞧自己和自己的学历。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务