#include #include using namespace std; struct box { int white, black; } B[100005]; bool cmp(box a, box b) { return a.white > b.white; } int main() { int n, m, w, b; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> B[i].white >> B[i].black; sort(B+1, B+n+1, cmp); for (int i = 1; i <= n; i++) if (i <= n/2) w += B[i].white; else b += B[i].black; cout << w << " " << b << "\n"; return 0; }