#include #include #include using namespace std; vector > vctMar; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; vctMar.push_back(make_pair(a, b)); } sort(vctMar.begin(), vctMar.end()); int sol1 = 0, sol2 = 0; for (int i = 0; i < n / 2; i++) sol1 += vctMar[i].second; for (int i = n / 2; i < n; i++) sol2 += vctMar[i].first; cout << sol1 << " " << sol2; return 0; }