-
Notifications
You must be signed in to change notification settings - Fork 1
/
1126.cc
69 lines (62 loc) · 1.52 KB
/
1126.cc
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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef const ll cll;
typedef queue<ll> qll;
typedef queue<pll> qpll;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll> pqpll;
typedef vector<ll> vll;
cll MAX_NUM = 5 * 1e5, MAX_SUM = MAX_NUM;
ll n, maxSum, dp[MAX_SUM + 1][51] = {{}};
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
dp[0][0] = 1, maxSum = 0;
cin >> n;
for (ll num, i = 0; i < n; ++i)
{
cin >> num;
for (ll sum, _sum = maxSum; _sum >= 0; --_sum)
{
if (!dp[_sum][0])
{
continue;
}
sum = num + _sum, maxSum = max(maxSum, sum);
for (ll bitMsk, idx = 1; idx <= dp[_sum][0]; ++idx)
{
dp[sum][++dp[sum][0]] = dp[_sum][idx] | (1 << i);
}
}
}
ll result = -1;
for (ll s = 0; s <= maxSum; ++s)
{
if (dp[s][0] < 2)
{
continue;
}
// cout << s << " : ";
for (ll i = 1; i < dp[s][0]; ++i)
{
for (ll l = i + 1; l <= dp[s][0]; ++l)
{
// cout << (dp[s][i] & dp[s][l]) << " ";
if (!(dp[s][i] & dp[s][l]))
{
result = s;
break;
}
}
}
// cout << "\n";
}
cout << result << "\n";
return 0;
}