Educational Codeforces Round 60 (Rated for Div. 2) A. Best Subsegment

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

You are given array

a

1

,

a

2

,…,

a

n

a1,a2,…,an

. Find the subsegment

a

l

,

a

l+1

,…,

a

r

al,al+1,…,ar

(

1≤l≤r≤n

1≤l≤r≤n

) with maximum arithmetic mean

1

r?l+1

i=l

r

a

i

1r?l+1∑i=lrai

(in floating-point numbers, i.e. without any rounding).

If there are many such subsegments find the longest one.

Input

The first line contains single integer

n

n

(

1≤n≤

10

5

1≤n≤105

) — length of the array

a

a

.

The second line contains

n

n

integers

a

1

,

a

2

,…,

a

n

a1,a2,…,an

(

0≤

a

i

10

9

0≤ai≤109

) — the array

a

a

.

Output

Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean.

Example

Input

Copy

5

6 1 6 6 0

Output

Copy

2

Note

The subsegment

[3,4]

[3,4]

is the longest among all subsegments with maximum arithmetic mean.

题解:,题目条件的意思就是区间的平均值,我们知道,区间平均值是肯定小于等于区间内的最大值,所以我们干脆就去最大值就好了,当然如果还有最大值连续的区间,那我们就取那个最大的长度.如 数列 6 1 6 6 0,有 6 和 6 6,取最长的就是 6 6 ,长度为2.

#include <bits/stdc++.h>
const int N=1e5+5;

using namespace std;
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    int maxn=-1;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]>maxn) maxn=a[i];
        //cout<<maxn<<endl;
    }
    int len=0;
    int ans=0;

    for(int i=1;i<=n;i++){
        if(a[i]==maxn) ans++;
        else{
            if(ans>len) len=ans;

            ans=0;
        }
    }
    if(ans>len) len=ans;
    printf("%d\n",len);
    //cout << "Hello world!" << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/-yjun/p/10427607.html

时间: 2024-11-02 18:59:19

Educational Codeforces Round 60 (Rated for Div. 2) A. Best Subsegment的相关文章

Educational Codeforces Round 60 (Rated for Div. 2)

A. Best Subsegment 题意 找 连续区间的平均值  满足最大情况下的最长长度 思路:就是看有几个连续的最大值 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn= 1e5+4; 4 int a[maxn]; 5 int main(){ 6 int n; 7 scanf("%d",&n); 8 int maxnum=0; 9 for(int i=0;i<n;i++)s

Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String

题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3次后你需要猜出这个字符串.解法是学习https://blog.csdn.net/baiyifeifei/article/details/87807822 这个博主的,借用了进制的思想非常巧妙. 解法:对于某个位置的来源位置我们设为x,因为26*26*26>10000,那么x可以唯一表示为x=a*26

Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems(矩阵快速幂)

题目传送门 题意: 一个魔法水晶可以分裂成m个水晶,求放满n个水晶的方案数(mol1e9+7) 思路: 线性dp,dp[i]=dp[i]+dp[i-m]; 由于n到1e18,所以要用到矩阵快速幂优化 注意初始化 代码: #include<bits/stdc++.h> using namespace std; #define mod 1000000007 typedef long long ll; #define MAX 105 const int N=105;//矩阵的大小 int T; ll

Educational Codeforces Round 60 (Rated for Div. 2)E(思维,哈希,字符串,交互)

#include <bits/stdc++.h>using namespace std;int main(){ string t; cin>>t; int n=t.size(); string s1(n,'a'),s2(n,'a'),s3(n,'a'); for(int i=0;i<n;i++){  s1[i]=char('a'+(i%26));//从a到z循环  s2[i]=char('a'+((i/26)%26));//第i位为(i/26)%26+'a',保证了26*26

Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)

#include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long long,long long>mp;long long n,m;long long dp(long long n){    if(n<0)        return 0;    if(n<m)        return 1;    if(mp.find(n)!=mp.end())//已经

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.