E. Wrong Answer
1 second
256 megabytes
standard input
standard output
Consider the following problem: given an array aa containing nn integers (indexed from 00 to n−1n−1), find max0≤l≤r≤n−1∑l≤i≤r(r−l+1)⋅aimax0≤l≤r≤n−1∑l≤i≤r(r−l+1)⋅ai. In this problem, 1≤n≤20001≤n≤2000 and |ai|≤106|ai|≤106.
In an attempt to solve the problem described, Alice quickly came up with a blazing-fast greedy algorithm and coded it. Her implementation in pseudocode is as follows:
function find_answer(n, a)
# Assumes n is an integer between 1 and 2000, inclusive
# Assumes a is a list containing n integers: a[0], a[1], ..., a[n-1]
res = 0
cur = 0
k = -1
for i = 0 to i = n-1
cur = cur + a[i]
if cur < 0
cur = 0
k = i
res = max(res, (i-k)*cur)
return res
Also, as you can see, Alice's idea is not entirely correct. For example, suppose n=4n=4 and a=[6,−8,7,−42]a=[6,−8,7,−42]. Then, find_answer(n, a) would return 77, but the correct answer is 3⋅(6−8+7)=153⋅(6−8+7)=15.
You told Alice that her solution is incorrect, but she did not believe what you said.
Given an integer kk, you are to find any sequence aa of nn integers such that the correct answer and the answer produced by Alice's algorithm differ by exactly kk. Note that although the choice of nn and the content of the sequence is yours, you must still follow the constraints earlier given: that 1≤n≤20001≤n≤2000 and that the absolute value of each element does not exceed 106106. If there is no such sequence, determine so.
The first and only line contains one integer kk (1≤k≤1091≤k≤109).
If there is no sought sequence, print "-1".
Otherwise, in the first line, print one integer nn (1≤n≤20001≤n≤2000), denoting the number of elements in the sequence.
Then, in the second line, print nn space-separated integers: a0,a1,…,an−1a0,a1,…,an−1 (|ai|≤106|ai|≤106).
8
4
6 -8 7 -42
612
7
30 -12 -99 123 -2 245 -300
The first sample corresponds to the example given in the problem statement.
In the second sample, one answer is n=7n=7 with a=[30,−12,−99,123,−2,245,−300]a=[30,−12,−99,123,−2,245,−300], in which case find_answer(n, a)returns 10981098, while the correct answer is 17101710.
E. Wrong Answer的更多相关文章
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- Stack Overflow is a question and answer site
http://stackoverflow.com/ _ Stack Overflow is a question and answer site for professional and enthus ...
- SPOJ GSS2 Can you answer these queries II
Time Limit: 1000MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description Being a ...
- Question and Answer
1.VS2013使用EntityFrame问题解决办法 解决办法参照博客http://pinter.org/?p=2374 使用到EntityFrame的项目配置文件修改如下: 项目中凡是使用到DbC ...
- 转 https://www.zhihu.com/question/27606493/answer/37447829
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:梁川链接:https://www.zhihu.com/question/27606493/answer/37447829来源: ...
- hdu 4027 Can you answer these queries?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...
- GSS4 2713. Can you answer these queries IV 线段树
GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...
- GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树
GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...
- GSS6 4487. Can you answer these queries VI splay
GSS6 Can you answer these queries VI 给出一个数列,有以下四种操作: I x y: 在位置x插入y.D x : 删除位置x上的元素.R x y: 把位置x用y取替 ...
- GSS5 spoj 2916. Can you answer these queries V 线段树
gss5 Can you answer these queries V 给出数列a1...an,询问时给出: Query(x1,y1,x2,y2) = Max { A[i]+A[i+1]+...+A[ ...
随机推荐
- [原创]java读写word文档,完美解决方案
做项目的过程中,经常需要把数据里里的数据读出来,经过加工,以word格式输出. 在网上找了很多解决方案都不太理想,偶尔发现了PageOffice,一个国产的Office插件,开发调用非常简单!比网上介 ...
- 从free到page cache
Free 我们经常用free查看服务器的内存使用情况,而free中的输出却有些让人困惑,如下: 图1-1 先看看各个数字的意义以及如何计算得到: free命令输出的第二行(Mem):这行分别显示了 ...
- 可视化工具Grafana部署
随着业务的越发复杂,对软件系统的要求越来越高,这意味着我们需要随时掌控系统的运行情况.因此,对系统的实时监控以及可视化展示,就成了基础架构的必须能力. Grafana官方网站 https://graf ...
- Linux 常用命令十二 top
一.top命令 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. top显示系统当前的进程和其他状况,是一个动态显示过程,即可以 ...
- Linux 常用命令九 tar
一.tar命令 tar命令用于打包,解包. gzip命令用于压缩,解压缩. bzip2命令用于压缩,解压缩. 这三个是在linux中常用的,还有一些不常用的. tar打包: wang@wang:~/w ...
- [App Store Connect帮助]七、在 App Store 上发行(3.3)提交至“App 审核”:解决 App 拒绝问题
如果“App 审核”或“Beta 版 App 审核”拒绝了您的 App,您可以与 Apple 沟通并在解决方案中心中解决问题. 来自 Apple 的通讯信息包含有关 App 拒绝的信息,其中包括该 A ...
- centos mysql数据库忘记密码修改
1.vim /etc/my.cnf 2.在[mysqld]中添加 skip-grant-tables 例如: [mysqld]skip-grant-tablesdatadir=/var/lib/mys ...
- saltstack实战笔记
#运维管理工具 ansible #支持ssh,不需要客户端 saltstack #也是只是ssh,不需要客户端的 安装架构是,master /minion 安装salt的依赖模块 python zer ...
- CF1119F Niyaz and Small Degrees
题意 给你\(n\)个点的树,边有边权 问使得所有的点度数都小于等于\(x\)的最小删边的代价 \([x \in 0...n-1]\) 题解 首先对于每个\(x\) 可以有一个\(O(nlogn)\) ...
- _bzoj2002 [Hnoi2010]Bounce 弹飞绵羊【分块】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 见一周目记录:http://www.cnblogs.com/ciao-sora/p/6 ...