-
Notifications
You must be signed in to change notification settings - Fork 0
/
339B.cpp
62 lines (61 loc) · 1.3 KB
/
339B.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
#define mod 1000000007
#define FOR(i, a, b) for (i = a; i < b; i++)
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef priority_queue<ll, vector<ll>, greater<ll>> minheap;
typedef priority_queue<ll> maxheap;
int dxrow[] = {-1, 0, 0, 1, 1, 1, -1, -1}; //first 4 straight last 4 diagonals
int dycol[] = {0, -1, 1, 0, 1, -1, -1, 1};
void printV(vector<ll> v)
{
for (ll i = 0; i < v.size(); i++)
cout << v[i] << "\n";
}
ll power(ll a, ll b)
{
return (ll)(pow(a, b) + 0.5);
}
int modexp(ll A, ll B, ll C)
{
if (A == 0)
return 0;
if (B == 0)
return 1;
ll y;
if (B % 2 == 0)
{
y = modexp(A, B / 2, C);
y = (y * y) % C;
}
else
{
y = A % C;
y = (y * modexp(A, B - 1, C) % C) % C;
}
return (ll)((y + C) % C);
}
int main()
{
ll n, m;
cin >> n >> m;
ll a[m];
for (ll i = 0; i < m; i++)
cin >> a[i];
ll ans = a[0] - 1;
for (ll i = 1; i < m; i++)
{
if (a[i] >= a[i - 1])
ans += (a[i] - a[i - 1]);
else
{
ans += (n - a[i - 1] + a[i]);
}
}
cout << ans;
}