forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14888_1.cpp
37 lines (33 loc) · 815 Bytes
/
14888_1.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
// Authored by : SciEm
// Co-authored by : -
// http://boj.kr/d1e716682fbe499881cd32ec1c235f7e
#include <bits/stdc++.h>
using namespace std;
int nums[12];
int ops[12]; // ops[0]은 항상 더하기
int n;
int mn = 0x7f7f7f7f, mx = -0x7f7f7f7f;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> nums[i];
for (int op = 0, idx = 1; op < 4; op++) {
int x; cin >> x;
while (x--)
ops[idx++] = op;
}
do {
int res = 0;
for (int i = 0; i < n; i++) {
if (ops[i] == 0) res += nums[i];
else if (ops[i] == 1) res -= nums[i];
else if (ops[i] == 2) res *= nums[i];
else res /= nums[i];
}
mx = max(mx, res);
mn = min(mn, res);
} while (next_permutation(ops + 1, ops + n));
cout << mx << '\n' << mn;
}