blob: f197e6ba916063f34fe0bddc0f3c3bd80c6fdd2c (
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
|
#include <iostream>
int batteries[1000];
int main(void) {
int N, K;
std::cin >> N >> K;
for (int i = 0; i < N; i++)
std::cin >> batteries[i];
int max = 0;
int max_index[4];
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
for (int k = j + 1; k < N; k++) {
for (int l = k + 1; l < N; l++) {
int sum = batteries[i] + batteries[j] + batteries[k] + batteries[l];
if (sum % K == 0 && sum > max) {
max = sum;
max_index[0] = i;
max_index[1] = j;
max_index[2] = k;
max_index[3] = l;
}
}
}
}
}
std::cout << max;
return 0;
}
|