Untitled
unknown
c_cpp
10 months ago
865 B
19
Indexable
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define FIN(x) freopen(x, "r", stdin)
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0)
#define SZ(x) (sizeof(x) / sizeof(*x))
#define endl '\n'
typedef long long ll;
template <typename T> void print(T &v) {
for (auto x : v)
cout << x << ' ';
cout << endl;
}
// clang-format on
int a[200000];
int main() {
// FIN("input.txt");
FASTIO;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
int negCount = 0;
int mi = INT_MAX;
ll sum = 0;
for (int i = 0; i < n; i++) {
if (a[i] < 0)
negCount++;
mi = min(mi, abs(a[i]));
sum += abs(a[i]);
}
if (negCount % 2 == 0) {
cout << sum << endl;
} else {
cout << sum - 2 * mi << endl;
}
}
return 0;
}
Editor is loading...
Leave a Comment