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-28 13:25
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
6539次浏览 63人参与
# 你的实习产出是真实的还是包装的? #
1304次浏览 32人参与
# 巨人网络春招 #
11213次浏览 223人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7077次浏览 37人参与
# 简历第一个项目做什么 #
31329次浏览 315人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186521次浏览 1115人参与
# 米连集团26产品管培生项目 #
4732次浏览 206人参与
# 研究所笔面经互助 #
118787次浏览 577人参与
# 面试紧张时你会有什么表现? #
30416次浏览 188人参与
# 简历中的项目经历要怎么写? #
309572次浏览 4163人参与
# 职能管理面试记录 #
10722次浏览 59人参与
# AI时代,哪些岗位最容易被淘汰 #
62757次浏览 749人参与
# 网易游戏笔试 #
6374次浏览 83人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
6993次浏览 154人参与
# 腾讯音乐求职进展汇总 #
160437次浏览 1107人参与
# 从哪些方向判断这个offer值不值得去? #
56712次浏览 357人参与
# 正在春招的你,也参与了去年秋招吗? #
362741次浏览 2632人参与
# 你怎么看待AI面试 #
179417次浏览 1182人参与
# 小红书求职进展汇总 #
226905次浏览 1357人参与
# 你的房租占工资的比例是多少? #
92146次浏览 896人参与
# 校招笔试 #
467654次浏览 2954人参与
# 经纬恒润求职进展汇总 #
155713次浏览 1085人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务