Movie Critics CodeForces - 250C

20 篇文章 0 订阅

A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.

On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once.

Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site.

As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress.

Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies.

Valentine wants to choose such genre x (1 ≤ x ≤ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum.

Input

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 105), where n is the number of movies and k is the number of genres.

The second line of the input contains a sequence of n positive integers a1a2, ..., an (1 ≤ ai ≤ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence.

Output

Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.

Example
Input
10 3
1 1 2 3 2 3 3 1 1 3
Output
3
Input
7 3
3 1 3 2 3 1 2
Output
1

思路:对于删掉当前的数,查看一下它的贡献有多少,然后对于每个数都累积。

然后这个方法还不全面,譬如说1 1 2 3当删掉第二个1的时候,很明显后面的2有贡献,然后第一个1和后面的2会减掉一个贡献,然而实际上我们删掉的是1.也就是我们需要找到前面第一个不等于1的数查看。所以总结一下,我们要把连续的数字给去重,只留下一个,然后查看他们的贡献就可以了。

#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+7;
int n,k;
int ha[MAXN];
int num[MAXN];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i)scanf("%d",&num[i]);
    n=unique(num,num+n)-num;
    for(int i=0;i<n;++i)
    {
        if(i-1>=0&&num[i]!=num[i-1])ha[num[i]]++;
        if(i+1<n&&num[i]!=num[i+1])ha[num[i]]++;
        if(i>=1&&i<n-1&&num[i-1]!=num[i+1])ha[num[i]]--;
    }
    int ans;
    int MAX=0;
    for(int i=1;i<=k;++i)
    {
        if(ha[i]>MAX)
        {
            MAX=ha[i];
            ans=i;
        }
    }
    printf("%d\n",ans);
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值