-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14888.cpp
More file actions
49 lines (44 loc) · 1.07 KB
/
Copy path14888.cpp
File metadata and controls
49 lines (44 loc) · 1.07 KB
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
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
int sym[4];
int n, k;
long long int x=1000000001, y=-1000000001;
vector <int> arr;
void run(int cnt, long long int sum, int a, int b, int c, int d){
// printf("%d %d %d %d %d %d\n", cnt, sum, a, b, c, d);
if(cnt==n){
x = min(x,sum);
y = max(y,sum);
return;
}
if(a>0){
run(cnt+1, sum+arr[cnt], a-1, b, c, d);
}
if(b>0){
run(cnt+1, sum-arr[cnt], a, b-1, c, d);
}
if(c>0){
run(cnt+1, sum*arr[cnt], a, b, c-1, d);
}
if(d>0){
run(cnt+1, sum/arr[cnt], a, b, c, d-1);
}
}
int main() {
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d", &k);
arr.push_back(k);
}
for(int i=0; i<4; i++){
scanf("%d", &k);
sym[i] = k;
}
// printf("%d %d %d %d %d %d\n", 1, arr[0], sym[0], sym[1], sym[2], sym[3]);
run(1, arr[0], sym[0], sym[1], sym[2], sym[3]);
printf("%lld\n%lld", y,x);
return 0;
}