Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <queue>
- #include <vector>
- #include <map>
- #include <set>
- #include <unordered_set>
- #include <stack>
- #include <iomanip>
- #include <cstring>
- #include <string>
- #include <cstdio>
- // #include <bits/stdc++.h>
- #pragma GCC push_options
- #pragma GCC optimize ("O0")
- using namespace std;
- typedef string str;
- typedef long long ll;
- typedef double db;
- typedef long double ld;
- typedef unsigned long long ull;
- typedef pair <int, int> pii;
- typedef pair <ll, ll> pll;
- typedef pair <db, db> pdd;
- typedef pair <ld, ld> pld;
- typedef ll var;
- typedef pair <var, var> pvv;
- #define sync ios_base::sync_with_stdio(false)
- #define printbool cout << (solve() ? "YES" : "NO") << '\n'
- #define updiv(ad, bd) (((ad - 1) / bd ) + 1)
- #define mod(ad, bd) ((((ad) % (bd)) + (bd)) % (bd))
- #define mxz(ad, bd) ad = max( ad, bd )
- #define mnz(ad, bd) ad = min( ad, bd )
- #define maxx(ad, bd, c) max(ad, max(bd, c))
- #define minn(ad, bd, c) min(ad, min(bd, c))
- #define arr(ad, bd, cd) (ad + bd), (ad + bd +cd)
- #define all(ad) ad.begin(), ad.end()
- #define sorts(ad) sort(all(ad))
- #define sorta(ad, bd, cd) sort(arr(ad, bd, cd))
- #define rvs(ad) reverse(all(ad))
- #define rva(ad, bd, cd) reverse(arr(ad, bd, cd))
- #define gl(ad) getline(cin, ad)
- #define wfloat(ad) fixed << setprecision(ad)
- #define pr(ad, bd) pair <(ad), (bd)>
- #define mlx(ad, bd) max(1ll * (ad), 1ll * (bd))
- #define mln(ad, bd) min(1ll * (ad), 1ll * (bd))
- template <typename T>
- inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }
- #define SD "\033[1m\033[31m"
- #define ED "\033[0m"
- #define RESET "\033[0m"
- #define BLACK "\033[30m" /* Black */
- #define RED "\033[31m" /* Red */
- #define GREEN "\033[32m" /* Green */
- #define YELLOW "\033[33m" /* Yellow */
- #define BLUE "\033[34m" /* Blue */
- #define MAGENTA "\033[35m" /* Magenta */
- #define CYAN "\033[36m" /* Cyan */
- #define WHITE "\033[37m" /* White */
- #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
- #define BOLDRED "\033[1m\033[31m" /* Bold Red */
- #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
- #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
- #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
- #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
- #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
- #define BOLDWHITE "\033[1m\033[37m" /* Bold White */
- #define sdebug cout << BOLDRED
- #define edebug cout << RESET
- #ifdef DEBUG
- void debug(const auto &c, const auto &e, const auto &... r) {
- cout << c << e;
- ((cout << " " << r), ..., (cout << ED << endl));
- }
- void dout(const auto &c, const auto &e, const auto &... r) {
- cout << c << e;
- ((cout << " " << r), ..., (cout << ED << " "));
- }
- #else
- #define debug(...)
- #define dout(...)
- #endif
- // cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
- #define rv reverse
- #define cl clear
- #define nl endl
- #define pb push_back
- #define pf push_front
- #define ppb pop_back
- #define ppf pop_front
- #define pu push
- #define pp pop
- #define in insert
- #define er erase
- #define mp make_pair
- #define popcnt __builtin_popcount
- #define np next_permutation
- #define lb lower_bound // <=
- #define ub upper_bound // <
- #define rand mt19937_64
- #define tp top
- #define ft front
- #define et empty
- #define sz size
- #define op operator
- #define f first
- #define s second
- #define y1 yyyyy
- #define cont continue
- // #define x first
- // #define y second
- // freopen("text.in", "r", stdin);
- // freopen("text.out", "w", stdout);
- // pii dr[8] = { mp(2, 1), mp(2, -1), mp(-2, 1), mp(-2, -1), mp(1, 2), mp(1, -2), mp(-1, 2), mp(-1, -2) };
- const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
- const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
- const ll LINF = 1e18; //infinity
- const double EPS = 1e-6 ; //epsilon
- const double PI = 3.14159; //pi
- const ll B = 31 ; //hashbase
- const ll LG = 11; //logarithm
- const ll INF = 1e9; //infinity
- const ll M = 1e9 + 7; //mod
- const ll N = 1e6 + 9; //maxn
- int n;
- int a[N];
- set <int> v;
- map <int, int> ma;
- int ans = -1;
- void solve(int l, int r, int i) {
- if (i == n/2+1) {
- v.in(l-r);
- mxz(ma[l-r], r);
- return;
- }
- solve(l+a[i], r, i+1);
- solve(l, r+a[i], i+1);
- solve(l, r, i+1);
- }
- void solve2(int l, int r, int i) {
- if (i == n+1) {
- if (v.find(r-l) != v.end()) {
- if (r+ma[r-l] > 0)
- mxz(ans, r+ma[r-l]);
- }
- return;
- }
- solve2(l+a[i], r, i+1);
- solve2(l, r+a[i], i+1);
- solve2(l, r, i+1);
- }
- int main() {
- sync;
- cin >> n;
- for (int i = 1; i <= n; ++i) {
- cin >> a[i];
- }
- solve(0, 0, 1);
- solve2(0, 0, n/2+1);
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement