339B codeforces Xenia and ringroad




339B codeforces 


Xenia and ringroad


#include <iostream>

#include <deque>

using namespace std;

long long int n,m,my=1,s=0;

deque<long long int>dk;

int main()

{

   cin>>n>>m;

   for(int i=0;i<m;i++){int t;cin>>t;dk.push_front(t);}

    while(dk.back()==1)dk.pop_back();

    while(!dk.empty()){

        s+=(my==dk.back())?n:(my<dk.back())?dk.back()-my:n-(my-dk.back());

        my=dk.back();

        do{

            dk.pop_back();

        }

         while(my==dk.back());

    }

    cout<<s<<"\n";

    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 التعليقات:

إرسال تعليق