C. Remove Extra One
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible.

We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≤ j < i) the following holds:aj < ai.

Input

The first line contains the only integer n (1 ≤ n ≤ 105) — the length of the permutation.

The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation. All the integers are distinct.

Output

Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.

Examples
input
1
1
output
1
input
5
5 1 2 3 4
output
5
Note

In the first example the only element can be removed.

【代码】:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int mx,mx2,n,mn=-1e9,res;
int a[N];
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
int x;
scanf("%d",&x);
if(x>mx)
{
mx2=mx;
mx=max(mx,x);
a[x]--;
}
else if(x>mx2)
{
a[mx]++;
mx2=max(mx2,x);
}
}
for(int i=;i<=n;i++)
{
if(a[i]>mn)
{
mn=a[i];
res=i;
}
}
cout<<res<<endl;
return ;
}

Codeforces Round #450 (Div. 2) C. Remove Extra One【*模拟链表/一个数比前面所有数大就是个record。删掉一个数,让record的个数尽量多。】的更多相关文章

  1. Codeforces Round #450 (Div. 2) C. Remove Extra One

    题目链接 题意:让你去掉一个数,使得剩下的数的record最多,当1≤j<i的aj<ai1 \leq j< i的a_j<a_i1≤j<i的aj​<ai​时aia_i ...

  2. Codeforces Round #450 (Div. 2) A. Find Extra One【模拟/判断是否能去掉一个点保证剩下的点在Y轴同侧】

    A. Find Extra One time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces Round #450 (Div. 2)

    Codeforces Round #450 (Div. 2) http://codeforces.com/contest/900 A #include<bits/stdc++.h> usi ...

  4. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  5. Codeforces Round #450 (Div. 2) ABCD

    这次还是能看的0 0,没出现一题掉分情况. QAQ前两次掉分还被hack了0 0,两行清泪. A. Find Extra One   You have n distinct points on a p ...

  6. 【Codeforces Round #450 (Div. 2) C】Remove Extra One

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举删除第i个数字. 想想删掉这个数字后会有什么影响? 首先,如果a[i]如果是a[1..i]中最大的数字 那么record会减少1 ...

  7. 【Codeforces Round #450 (Div. 2) A】Find Extra One

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟. 看看Y左边或右边的点个数是否<=1 [代码] #include <bits/stdc++.h> using ...

  8. Codeforces Round #605 (Div. 3) D. Remove One Element(DP)

    链接: https://codeforces.com/contest/1272/problem/D 题意: You are given an array a consisting of n integ ...

  9. Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)

    题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_ ...

随机推荐

  1. 笔记-python-standard library-8.10 copy

    笔记-python-standard library-8.10 copy 1.      copy source code:Lib/copy.py python中的赋值语句不复制对象,它创建了对象和目 ...

  2. Markdowm语法学习

    Markdowm语法学习 标题 一级标题 一级标题 #一级标题 二级标题 二级标题 ##二级标题 六级标题 六级标题 ######六级标题 引用 引用 >引用 代码块 if(i == 0) { ...

  3. python上数据存储 .h5格式或者h5py

    最近在做城市计算的项目,数据文件是以.h5的格式存储的,总结下其用法和特点 来自百度百科的简介: HDF(Hierarchical Data Format),可以存储不同类型的图像和数码数据的文件格式 ...

  4. Neural Network

    逻辑回归用神经网络节点的方式表示 前面已经介绍过逻辑回归的模型,样本为(x,y) 其中y的值为1或0,假设x有2个特征,则对应关系如下图所示.  实际情况是需要求需要三个参数,因此输入层需要添加一个 ...

  5. mongo命令

    安装mongo http://docs.mongodb.org/master/tutorial/install-mongodb-on-redhat-centos-or-fedora-linux/ 启动 ...

  6. Python+Selenium练习篇之2-利用ID定位元素

    在前面一篇文章,我们介绍了如何摘取页面字段,通过正则进行匹配符合要求的字段.如果感觉有点困难,不能立马理解,没有关系.把字符串摘取放到第一篇,是因为自动化测试脚本,经常要利用字符串操作,字符串切割,查 ...

  7. 实战项目——获取图片中的GPS位置信息和拍摄时间

    今天突然看到有人写过获取图片中位置信息的程序.我觉得很有趣,也就自己实践了一下,研究了一下 话不多说,先上代码 #!/usr/bin/env python3 # -*- coding: utf-8 - ...

  8. Zookeeper 增删改查

    初始化对象连接到zookeeper服务: public ZooKeeper initZk(){ final CountDownLatch countDownLatch = new CountDownL ...

  9. node中fileSystem改promise

    请注意,fs的大部分函数回调只会返回一个error参数,所以只要判断error为false的情况下就返回成功,无论有没有第二个参数. 另外exists需要单独包装,因为第一个参数就代表返回内容 con ...

  10. 【转】UGUI(小地图的实现)与游戏关卡选择的简单实现

    http://www.jianshu.com/p/68637029e9df 游戏中小地图的实现(场景用简单Cube组成先搭建如下图场景,真实场景实现方法也是一样) 图1-1小地图效果图 1.创建好场景 ...