#include #include #include #include using namespace std; vector num; vector op; vector nums; int GetMax(int p, int m) { int res = 0; for (int i = 0; i < nums.size(); ++i) { if (p > 0) { res += nums[i]; --p; } else if (m > 0) { res -= nums[i]; --m; } } return res; } int GetMin(int p, int m) { int res = 0; for (int i = 0; i < nums.size(); ++i) { if (m > 0) { res -= nums[i]; --m; } else if (p > 0) { res += nums[i]; --p; } } return res; } int main(void) { int N; cin >> N; int opCnt = 0; int pCnt = 1; int mCnt = 0; for (int i = 0; i < N; ++i) { string s; cin >> s; if (s == "+") ++pCnt; else if (s == "-") ++mCnt; else num.push_back(s); } int numCnt = pCnt + mCnt; sort(num.begin(), num.end()); reverse(num.begin(), num.end()); string s; for (int i = 0; i < (num.size() - (pCnt+mCnt-1)); ++i) { s += num[i]; } nums.push_back(atoi(s.c_str())); for (int i = num.size() - (pCnt+mCnt-1); i < num.size(); ++i) { nums.push_back(atoi(num[i].c_str())); } cout << GetMax(pCnt, mCnt) << " " << GetMin(pCnt, mCnt) << endl; return 0; }