#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define SZ(x) ((int) (x).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(x) cerr << "[" << #x << " = " << (x) << "]" << endl
#define left __left
#define right __right
#define prev __prev
#define fi first
#define se second
template <class X, class Y>
bool maximize(X &x, Y y) {
if (x < y) return x = y, true;
else return false;
}
template <class X, class Y>
bool minimize(X &x, Y y) {
if (x > y) return x = y, true;
else return false;
}
int numNotes;
#define MAX_NOTES 505
int cost[MAX_NOTES + 2];
namespace subtask1 {
bool check() {
return (numNotes <= 13);
}
int rem, answer;
vector <int> arr;
void dq(int i) {
if (i > numNotes) {
int A = 0, B = 0, sum = 0;
FOR(j, 0, numNotes - 1) {
if (arr[j] == 1) A += cost[j + 1];
else if (arr[j] == 2) B += cost[j + 1];
sum += cost[j + 1];
}
if (A == B && minimize(rem, sum - A - B)) {
// answer = A + sum - A - B;
answer = sum - A;
}
return;
}
FOR(state, 0, 2) {
arr.push_back(state);
dq(i + 1);
arr.pop_back();
}
}
void solve() {
rem = int(1e9), answer = 0;
dq(1);
cout << answer;
}
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
cin >> numNotes;
FOR(i, 1, numNotes) cin >> cost[i];
if (subtask1 :: check()) return subtask1 :: solve(), 0;
return 0;
}
/* Discipline - Calm */
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |