#include #include #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); int n = 0, m = 0; cin >> n >> m; vector > v(n); for(auto& x : v){ cin >> x.first >> x.second; } nth_element(begin(v), begin(v) + n/2, end(v), [](const pair& s, const pair& d){ return s.first-s.second > d.first-d.second; }); cout << accumulate(begin(v), begin(v) + n/2, 0, [](const int x, const pair& rhs){return x + rhs.first; }) << ' ' << accumulate(begin(v) + n/2, end(v), 0, [](const int x, const pair& rhs){return x + rhs.second; }); return 0; }