-
Notifications
You must be signed in to change notification settings - Fork 0
/
14888.cpp
64 lines (56 loc) · 891 Bytes
/
14888.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
using namespace std;
int n;
int optr[4];
int arr[11];
int Max=-1000000001;
int Min=1000000001;
int calcul(int *arr,int i,int optr_idx,int result)
{
if(i<n-1){
if(!i)
result=arr[i];
switch(optr_idx)
{
case 0 : return result+arr[i+1];
case 1 : return result-arr[i+1];
case 2 : return result*arr[i+1];
case 3 : return result/arr[i+1];
default : return 0;
}
}
}
void oper(int *arr,int cnt,int result,int idx)
{
if(cnt==n-1)
{
if(result>Max&&result<=1000000000){
Max=result;
}
if(result<Min&&result>=-1000000000){
Min=result;
}
return;
}
for(int i=0;i<4;i++)
{
if(optr[i])
{
optr[i]--;
int tmp=calcul(arr,idx,i,result);
oper(arr,cnt+1,tmp,idx+1);
optr[i]++;
}
}
}
int main(void)
{
cin>>n;
for(int i=0;i<n;i++)
cin>>arr[i];
for(int i=0;i<4;i++)
cin>>optr[i];
oper(arr,0,0,0);
cout<<Max<<'\n';
cout<<Min;
}