Thứ Ba, 3 tháng 5, 2022

BIKM C++

#include <bits/stdc++.h>
using namespace std;
int maxx,n,k,x,a[10000000],d[10000000];
void nhap()
{
    //scanf("%d %d",&n,&k);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        //scanf("%d",&a[i]);
    }    
}
void giai()
{
    maxx=-1;
    for(int i=1;i<=k+1;i++)
    {
        d[a[i]]++;
        if(d[a[i]]>1)
            if(a[i]>maxx) maxx=a[i];
    }
    for(int i=2;i<=n-k;i++)
    {
        d[a[i+k]]++;
        d[a[i-1]]--;
        if(d[a[i+k]]>1)
            if(a[i+k]>maxx) maxx=a[i+k];
    }
    cout << maxx;    
}


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    freopen("bikm.inp","r",stdin);
    freopen("bikm.out","w",stdout);
    nhap();
    giai();
   
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.