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[ ...
随机推荐
- 利用js和CSS实现网页局部打印
1 局部打印方法: 作用:将id为dayin的内容,新建页面并打印,可解决打印某页面中的部分内容的问题.使用方法:将要打印的内容通过 <span id="dayin"> ...
- Python基础第七天
一.内容 二.练习 练习1 题目:编写函数,函数执行的时间是随机的 图示: 代码: import time import random def func(): s = 1 l = [] for i i ...
- CentOS 6 网络设置修改 指定IP地址 DNS 网关
环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Centos-6.5-x86_64 路由器网关:192.168.1.1 步骤: 1.查看网络MAC地址 [ro ...
- lua 与 c 的相互调用
Lua是一个嵌入式的语言,意味着Lua不仅可以是一个独立运行的程序包也可以是一个用来嵌入其他应用的程序库. Lua可以作为程序库用来扩展应用的功能,也就是Lua可以作为扩展性语言的原因所在.同时,Lu ...
- UI:通讯录实现
通讯录实现草图: 代码: #pragma mark (.h文件)-------------------------------------------------------------------- ...
- ubuntu 12.04上安装QQ2013(转载)
转自:http://www.cnblogs.com/wocn/p/linux_ubuntu_QQ_install.html 环境介绍: OS:Ubuntu12.04 64bit QQ:WineQQ20 ...
- Centos6可以ping通但浏览器不能上网(解决)
遇到这种情况,只需要修改一下DNS Server即可,如下图. 这样再试试,应该可以了吧-
- bzoj 2660: [Beijing wc2012]最多的方案【dp】
有点神奇的dp 首先注意到任意一个数都能被表示成若干个斐波那契数的和的形式 先求出n可以字典序最大的表示 设f[i][0/1]表示第i个斐波那契数选或者不选 如果当前数不选,那就选比他小的两个数,否则 ...
- Luogu P1160队列安排【链表/老文搬家】By cellur925
原文发表于2018-04-15 08:15:09,我的luogu博客qwq. 看到题以后,要求维护一个可在任意位置修改添加删除元素的序列,那么显然我们可以用到链表. 然而本蒟蒻不久前刚刚学会链表.链表 ...
- [POI2007]对称轴osi
Description FGD小朋友--一个闻名遐迩的年轻数学家--有一个小MM,yours.FGD小朋友非常喜欢他的MM,所以他很乐意帮助他的MM做数学作业.但是,就像所有科学的容器一样,FGD的大 ...