#include #include #include using namespace std; int n; vector d; int maxStamina(unsigned int bits) { int result = 100; for (int i = 0; i < n; ++i) { if ((bits & (1 << i)) && d[i] < 0) { result += 100; } } return result; } int main() { cin >> n; d.resize(n); for (int i = 0; i < n; ++i) { cin >> d[i]; } vector stamina(1 << n); stamina[0x0] = 100; for (unsigned int bits = 0x0; bits < (1U << n); ++bits) { if (stamina[bits] == 0) { continue; } for (int next = 0; next < n; ++next) { if ((bits | (1 << next)) != bits) { int nextStamina = min(max(0, stamina[bits] + d[next]), maxStamina(bits)); unsigned int nextBits = bits | (1U << next); stamina[nextBits] = max(stamina[nextBits], nextStamina); } } } cout << stamina[(1 << n) - 1] << endl; return 0; }