time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Let's call an array of non-negative integers a1,a2,…,an a k-extension for some non-negative integer if for all possible pairs of indices 1≤i,j≤n the inequality k⋅|i−j|≤min(ai,aj) is satisfied. The expansion coefficient of the array is the maximal integer k such that the array is a k-extension. Any array is a 0-expansion, so the expansion coefficient always exists.

You are given an array of non-negative integers a1,a2,…,an. Find its expansion coefficient.

Input

The first line contains one positive integer — the number of elements in the array a (2≤n≤300000). The next line contains non-negative integers a1,a2,…,an, separated by spaces (0≤ai≤10^9).

Output

Print one non-negative integer — expansion coefficient of the array a1,a2,…,an.

Examples
input

4

6 4 5 5

output
1
 
input

3

0 1 2

output
0
 
input

4

821 500 479 717

output
239
 
Note

In the first test, the expansion coefficient of the array [6,4,5,5] is equal to because |i−j|≤min(ai,aj), because all elements of the array satisfy ai≥3. On the other hand, this array isn't a 2-extension, because 6=2⋅|1−4|≤min(a1,a4)=5 is false.

In the second test, the expansion coefficient of the array [0,1,2] is equal to because this array is not a 1-extension, but it is 0-extension.

题解

对于数列 a1,a2,…,an,分析其中任意一项ai,考虑所有的aj >= aiaj < ai的算在aj里面考虑了),则使得min(ai,aj) = ai,要使所有的j都满足k*|i-j| <= min(ai,aj) = ai,则对于ai来说,j应该尽量远离i,这样解出来的最大的k才是有用的(即对aik值的约束最紧)。显然最远的j应该是数列两端中的一端,但两端不一定大于ai。那怎么办呢?仔细一想,对于两端的情况,考虑最前端a1及最后端an

  1. 如果a1 >= ai,则对于当前ai来说,k要满足k <= ai/|i-1|(如果i == 1,则说明k值没有限制)。如果a1 < ai,则对于当前ai来说,k要满足k <= a1/|i-1| < ai/|i-1|
  2. 如果an >= ai,则对于当前ai来说,k要满足k <= ai/|i-n|(如果i == n,则说明k值没有限制)。如果an < ai,则对于当前ai来说,k要满足k <= an/|i-n| < ai/|i-n|
  3. 在所有大于等于aiaj中,k对于ai来说要满足k <= ai/|i-j|,而|i-j| <= |i-1||i-j| <= |i-n|,故ai/|i-1| <= ai/|i-j|ai/|i-n| <= ai/|i-j|

可见,对每项ai来说,考虑两端的项所解出来的k值必定有一项是有用的(即对aik值的约束最紧)。

枚举每一项求解出来的有用的k值,再取最小即得到最优答案。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <algorithm>
#define re register
#define il inline
#define ll long long
#define ld long double
const ll MAXN = 1e6+;
const ll INF = 1e9; //快读
il ll read()
{
char ch = getchar();
ll res = , f = ;
while(ch < '' || ch > '')
{
if(ch == '-') f = -;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
res = (res<<) + (res<<) + (ch-'');
ch = getchar();
}
return res*f;
} ll a[MAXN]; int main()
{
ll n = read();
for(re ll i = ; i <= n; ++i)
{
a[i] = read();
}
ll k = INF;
for(re ll i = ; i <= n; ++i)
{
k = std::min(i==?k:std::min(a[i],a[])/(i-),k);
k = std::min(i==n?k:std::min(a[i],a[n])/(n-i),k);
}
printf("%lld\n", k);
return ;
}

CodeForces-1159B-Expansion coefficient of the array的更多相关文章

  1. Codeforces 221d D. Little Elephant and Array

    二次联通门 : Codeforces 221d D. Little Elephant and Array /* Codeforces 221d D. Little Elephant and Array ...

  2. Codeforces Round #181 (Div. 2) A. Array 构造

    A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...

  3. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配

    题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...

  4. Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】

    传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...

  5. codeforces 558B. Amr and The Large Array 解题报告

    题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...

  6. CodeForces Round #179 (295A) - Greg and Array

    题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include < ...

  7. Codeforces 1105C: Ayoub and Lost Array(递推)

    time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...

  8. Codeforces 1114F Please, another Queries on Array? [线段树,欧拉函数]

    Codeforces 洛谷:咕咕咕 CF少有的大数据结构题. 思路 考虑一些欧拉函数的性质: \[ \varphi(p)=p-1\\ \varphi(p^k)=p^{k-1}\times (p-1)= ...

  9. Codeforces 1114F Please, another Queries on Array? 线段树

    Please, another Queries on Array? 利用欧拉函数的计算方法, 用线段树搞一搞就好啦. #include<bits/stdc++.h> #define LL ...

随机推荐

  1. Kali Linux硬盘扩容

    传送门--->http://www.kali.org.cn/thread-27079-1-1.html.kali虚拟机扩容

  2. 【纸模】六角大王 Super 5.6 CHS 简体中文版 U20080725+[手册]窗口与工具的概要(PDF格式)

    六角大王5.6简体中文版中文化:star21 主界面<ignore_js_op> 人体生成模式<ignore_js_op> 动画<ignore_js_op> < ...

  3. java判断A字符串中是否包含B字符

    java.lang.String类提供的方法 public boolean contains(CharSequence s) 当且仅当此字符串包含指定的 char 值序列时,返回 true. 例如: ...

  4. 设定rsync开机自启动

    1.启用rsync服务systemctl enable rsync 2.打开rsync自己的开关,这个找了好多地方才找到的vi /etc/default/rsyncRSYNC_ENABLE=true

  5. C3线性化

    https://zh.wikipedia.org/wiki/C3线性化 在计算机科学中,C3算法主要用于确定多重继承时,子类应该继承哪一个父类的方法,即方法解析顺序(Method Resolution ...

  6. iframe子页面无法返回上一页的问题

    本文讨论的场景是ipad终端. 如题,因业务需要,需要使用iframe嵌套子页面.让外层始终保持一个socket连接,避免socket每跳转一个页面都要重新关闭建立连接的问题.但是这样问题来了,上线后 ...

  7. Python3入门(十三)——常用内置模块之摘要模块hashlib/hmac

    (1)hashlib hashlib提供了常见摘要算法:如MD5,SHA1等等 一个md5的加密示例如下: import hashlib m = hashlib.md5() m.update(&quo ...

  8. 算法习题---5.6团体队列(Uva540)

    一:题目 有t个队伍的人正在排队,每次新来一个人,如果他有队友在排队,那他可以插队,直接排到他的队伍的末尾.如果没有队伍在前面,那么他直接排在长队的末尾 ENQUEUE x 将编号x的队员入队 DEQ ...

  9. 【JAVA】java注解的自定义和使用

    java注解概念 Java提供了一种原程序中的元素关联任何信息和任何数据的途径和方法 java注解介绍 常用注解 @Override:表示方法是重写的方法 @Deprecated:过时的方法 @Sup ...

  10. Qt编写气体安全管理系统24-地图管理

    一.前言 地图管理的主要功能是将系统中的地图文件做添加和删除,支持常见的jpg.png.bmp等格式图片,图片分辨率建议小于1080P,最好是和目标客户端电脑分辨率一致,这样在拉伸缩放的时候会比较清晰 ...