-
Notifications
You must be signed in to change notification settings - Fork 0
/
Large_Differences.cpp
62 lines (52 loc) · 1.14 KB
/
Large_Differences.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>
using namespace std;
#define ll long long int
#define rep(i, m, n) for (ll i = m; i < n; i++)
const ll INF = 1e9;
int solve(const vector<int> &a)
{
int sum = 0;
for (size_t i = 1; i < a.size(); ++i)
{
sum += abs(a[i] - a[i - 1]);
}
return sum;
}
int main()
{
int _;
cin >> _;
while (_--)
{
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i)
{
cin >> a[i];
}
int initialSum = solve(a);
int maxSum = initialSum;
for (int i = 0; i < n; ++i)
{
vector<int> temp = a;
if (i > 0)
{
temp[i] = 1;
int temp1 = solve(temp);
maxSum = max(maxSum, temp1);
temp[i] = k;
int temp2 = solve(temp);
maxSum = max(maxSum, temp2);
}
else
{
temp[i] = k;
int t1 = solve(temp);
maxSum = max(maxSum, t1);
}
}
cout << maxSum << endl;
}
return 0;
}