forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3657 - The Little Girl who Picks Mushrooms.cpp
69 lines (53 loc) · 1.5 KB
/
3657 - The Little Girl who Picks Mushrooms.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
65
66
67
68
69
#include <cstdio>
#include <algorithm>
using namespace std;
int a[5];
int solve4(){
int ret = 0,total = a[0] + a[1] + a[2] + a[3];
for(int i = 0;i < 2;++i)
for(int j = i + 1;j < 3;++j)
for(int k = j + 1;k < 4;++k)
if((a[i] + a[j] + a[k]) % 1024 == 0)
return 1024;
for(int i = 0;i < 3;++i){
for(int j = i + 1;j < 4;++j){
int sum = total - a[i] - a[j];
if(sum > 0){
sum %= 1024;
if(sum == 0) sum = 1024;
ret = max(ret,sum);
}
}
}
return ret;
}
int solve5(){
int ret = 0,total = a[0] + a[1] + a[2] + a[3] + a[4];
for(int i = 0;i < 3;++i){
for(int j = i + 1;j < 4;++j){
for(int k = j + 1;k < 5;++k){
int sum = a[i] + a[j] + a[k];
if(sum % 1024 == 0){
sum = total - sum;
if(sum > 0){
sum %= 1024;
if(sum == 0) sum = 1024;
ret = max(ret,sum);
}
}
}
}
}
return ret;
}
int main(){
int n;
while(scanf("%d",&n) == 1){
for(int i = 0;i < n;++i)
scanf("%d",&a[i]);
if(n <= 3) printf("1024\n");
else if(n == 4) printf("%d\n",solve4());
else printf("%d\n",solve5());
}
return 0;
}