-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlackslexandShowering.cpp
More file actions
41 lines (33 loc) · 911 Bytes
/
BlackslexandShowering.cpp
File metadata and controls
41 lines (33 loc) · 911 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
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) cin >> x;
int total = 0;
for (int i = 0; i + 1 < n; i++)
total += abs(a[i] - a[i + 1]);
int ans = total;
// Remove first
ans = min(ans, total - abs(a[0] - a[1]));
// Remove last
ans = min(ans, total - abs(a[n-2] - a[n-1]));
// Remove middle
for (int i = 1; i + 1 < n; i++) {
int cur = total
- abs(a[i] - a[i-1])
- abs(a[i] - a[i+1])
+ abs(a[i-1] - a[i+1]);
ans = min(ans, cur);
}
cout << ans << '\n';
}
return 0;
}