911 Codeforces - Nearest minimums


911A Codeforces - Nearest minimums






Solution in C++

#include <bits/stdc++.h>

using namespace std;

int n,bst=LONG_MAX,sol=LONG_MAX;
vector<int> all;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int nn[n];
    for(int i=0;i<n;i++)
    {
        cin>>nn[i];
        if(nn[i]<bst)
        {
            bst=nn[i];
            all.clear();
            all.push_back(i);
        } else if(nn[i]==bst){all.push_back(i);}
    }
    sort(all.begin(),all.end());
    for(int i=1;i<all.size();i++)
    {
        sol=min(sol,all[i]-all[i-1]);
    }
    cout<<sol;
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق