#include #include #include using namespace std; #define DIM 100005 int N, M; struct str{ int x, y; } V[DIM]; bool cmp(str a, str b) { return a.x > b.x; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif // ONLINE_JUDGE cin >> N >> M; for(int i = 1; i <= N; ++i) { cin >> V[i].x >> V[i].y; } sort(V + 1, V + 1 + N, cmp); int black, white; black = white = 0; for(int i = 1; i <= N / 2; ++i) { white += V[i].x; } for(int i = N / 2 + 1; i <= N; ++i) { black += V[i].y; } cout << black << ' ' << white << '\n'; return 0; }