-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathholder.cpp
More file actions
39 lines (32 loc) · 680 Bytes
/
Copy pathholder.cpp
File metadata and controls
39 lines (32 loc) · 680 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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
const int N = 2e5 + 11;
void solve() {
ll n, m;
cin >> n >> m;
ll holder;
ll curr = 1;
ll result = 0;
for (ll i = 0; i < m; i++) {
cin>>holder;
if( holder >= curr ) result += holder - curr;
else result += n - abs(holder - curr);
curr = holder;
}
cout<<result<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
freopen("input.txt", "r", stdin);
int no_of_test_cases = 1;
// cin >> no_of_test_cases;
while (no_of_test_cases--) execute();
return 0;
}