#include #include #include using namespace std; int main() { vector> bags; int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { int w, b; cin >> w >> b; bags.push_back(make_pair(w, b)); } sort(bags.begin(), bags.end(), [](const pair &lhs, const pair &rhs) { if (lhs.first != rhs.first) { return lhs.first > rhs.first; } else { return lhs.second > rhs.second; } }); int tw, tb; tw = tb = 0; for (int i = 0; i < n; ++i) { if (i < n / 2) { tb += bags[i].first; } else { tw += bags[i].second; } } cout << tb << " " << tw << "\n"; return 0; }