// header {{{ #include using namespace std; // {U}{INT,LONG,LLONG}_{MAX,MIN} #define INF INT_MAX/3 #define LLINF LLONG_MAX/3 #define MOD (1000000007LL) #define MODA(a, b) a=((a)+(b))%MOD #define MODP(a, b) a=((a)*(b))%MOD #define inc(i, l, r) for(long long i=(l);i<(r);i++) #define dec(i, l, r) for(long long i=(r)-1;i>=(l);i--) #define pb push_back #define se second #define fi first #define mset(a, b) memset(a, b, sizeof(a)) using LL = long long; using G = vector>; int di[] = {0, -1, 0, 1}; int dj[] = {1, 0, -1, 0}; // }}} int main() { std::ios::sync_with_stdio(false); int n, k;cin >> n >> k; vector t(n), d(n), flag(n, 1); priority_queue> pq; inc(i, 0, n){ cin >> t[i] >> d[i]; pq.push({d[i], i}); } int ansmax = 0; LL anssum = 0; while(!pq.empty()){ int i = pq.top().second; pq.pop(); if(!flag[i]) continue; flag[i] = false; for(int j=i+1;j= k) break; flag[j] = false; ansmax = max(ansmax, d[j]); anssum += d[j]; } for(int j=i-1;j>=0;j--){ if(!flag[j]) break; if(t[i]-t[j] >= k) break; flag[j] = false; ansmax = max(ansmax, d[j]); anssum += d[j]; } } cout << ansmax << endl; cout << anssum << endl; return 0; }