-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNegativesAndPositives.cpp
More file actions
43 lines (38 loc) · 922 Bytes
/
Copy pathNegativesAndPositives.cpp
File metadata and controls
43 lines (38 loc) · 922 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
42
43
// https://codeforces.com/problemset/problem/1791/E
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>
#include <cstdint>
#define ll long long
#define u64 uint64_t
#define i64 int64_t
using namespace std;
int main() {
int nC = 0;
cin >> nC;
for (int c = 0; c < nC; c++) {
int len = 0;
cin >> len;
vector<ll> a;
for (int i = 0; i < len; i++) {
ll input;
cin >> input;
a.push_back(input);
}
ll min = LLONG_MAX, ans = 0;
int negs = 0;
for (int i = 0; i < len; i++) {
if (a[i] <= 0)
negs++;
if (abs(a[i]) < min)
min = abs(a[i]);
ans += abs(a[i]);
}
ans -= (negs % 2 == 1) ? min*2 : 0;
cout << ans << '\n';
}
return 0;
}