Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul255 authored Nov 20, 2018
1 parent d555818 commit 401bf75
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 339B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#include <iostream>
using namespace std;
int main()
{
int n, m,value;
cin>>n>>m;
int count=0;
int pos = 1;
for(int i=0;i!=m;i++)
{
cin>>value;
if (value<pos)
{
count=count+(n-pos+value);
}
else
{
count=count+(value-pos);
}
pos=value;
}
cout<<count;
return 0;
}

0 comments on commit 401bf75

Please sign in to comment.