File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ // ॐ नमः शिवाय
2
+ #include < bits/stdc++.h>
3
+ using namespace std ;
4
+
5
+ #define ll long long
6
+ #define pb push_back
7
+ #define ff first
8
+ #define ss second
9
+ #define mp make_pair
10
+
11
+ // Code Written By: Vikash Patel
12
+ // Codeforces Profile: https://codeforces.com/profile/vikashpatel
13
+
14
+ int main ()
15
+ {
16
+ ios_base::sync_with_stdio (0 );
17
+ cin.tie (0 );
18
+ cout.tie (0 );
19
+
20
+ // #ifndef ONLINE_JUDGE
21
+ // freopen("input.txt", "r", stdin);
22
+ // freopen("/Users/vikash/Desktop/output.txt", "w", stdout);
23
+ // #endif
24
+
25
+ int n, m;
26
+ cin>>n>>m;
27
+ int a[m];
28
+ for (int i=1 ; i<=m; i++)
29
+ {
30
+ cin>>a[i];
31
+ }
32
+ long long time = a[1 ]-1 ;
33
+ for (int i=2 ; i<=m; i++)
34
+ {
35
+ if (a[i] < a[i-1 ])
36
+ time += (n-a[i-1 ] + a[i]);
37
+ if (a[i] > a[i-1 ])
38
+ time += (a[i]-a[i-1 ]);
39
+ }
40
+ cout<<time <<endl;
41
+ return 0 ;
42
+ }
You can’t perform that action at this time.
0 commit comments