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[ ...
随机推荐
- eclipse svn修改用户名密码
1,svn客户端删除 2,eclipse 补充,上图为网友资料,但实际操作过程中,发现eclipse中svn为svnkit,但相应目录下无.keyring文件,最后按步骤2删除auth下所有文件,再次 ...
- 专用于ASP.Net Web应用程序的日期控件
原文引入:http://blog.csdn.net/nileel/article/details/1566051 专用于ASP.Net Web应用程序的日期控件 分类: ASP.NET/C#2007 ...
- 工作中常用到的JS校验
1. // 验证是否为空 2. function check_blank(obj, obj_name){ 3. if(obj.value != ''){ 4. return true; 5. }els ...
- 关于追踪qemu 源码函数路径的一个方法
这阵子一直在研究qemu 磁盘io路径的源码,发现直接看代码是意见非常低效率的事情,qemu是一个比较庞大的家伙(源码部分大概154MB,完全由C语言来完成),整个结构也都非常地复杂,所以从代码上研究 ...
- CodeForces-204E:Little Elephant and Strings (广义后缀自动机求出现次数)
The Little Elephant loves strings very much. He has an array a from n strings, consisting of lowerca ...
- poj 3517(约瑟夫环问题)
And Then There Was One Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4873 Accepted: ...
- ExtJS4 带清除功能的文本框 triggerfield
Ext.onReady(function () { Ext.create('Ext.form.FormPanel', { title: 'Form with TriggerField', bodyPa ...
- SELinux的启动和关闭
1.SELinux简介 SELinux是Security Enhanced Linux的缩写,字面上的意思就是安全强化的Linux,它是由美国国家安全局 (NSA) 开发的,整合到Linux核心的一个 ...
- 【练习】Java实现的杨辉三角形控制台输出
import java.util.Scanner; /** * YangHui_tst01 * @author HmLy * @version 000 * - - - - - - - * 练习代码.( ...
- [Usaco2017 Open]Modern Art 2
Description Having become bored with standard 2-dimensional artwork (and also frustrated at others c ...