blob: 8d70a550f6ad82c938dd89e4bc3cf01c5e3398d2 (
plain)
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
|
#include <algorithm>
#include <iostream>
int N, K;
long long A[100010];
long long M = 1000000009;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> N >> K;
for (int i = 0; i < N; i++) {
std::cin >> A[i];
}
std::sort(A, A + N);
long long result = 1;
int left = 0, right = N - 1;
long long sign = 1;
int k = K;
if (k % 2) {
result = A[N - 1];
right--;
k--;
if (result < 0) {
sign = -1;
}
}
while (k) {
long long x = A[left] * A[left + 1], y = A[right] * A[right - 1];
if (x * sign > y * sign) {
result = x % M * result % M;
left += 2;
} else {
result = y % M * result % M;
right -= 2;
}
k -= 2;
}
std::cout << result;
return 0;
}
|