-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeforces_339B.cpp
More file actions
41 lines (35 loc) · 800 Bytes
/
codeforces_339B.cpp
File metadata and controls
41 lines (35 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Created by Rahul Sharma
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m;
cin>>n>>m;
vector<ll> v(m);
v[0]=1;
rep(i,m) cin>>v[i];
auto ip = unique(v.begin(), v.end());
v.resize(distance(v.begin(), ip));
ll count = 0;
count += v[0]-1;
for (ll i=0; i<v.size()-1; i++){
if (v[i+1]>v[i]){
if(i==v.size()-1){
cout << count;
return 0;
}
count += v[i+1] - v[i];
}
else
count += n + v[i+1] - v[i];
}
cout << count << '\n';
return 0;
}