#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct RestStop {
int distance;
int profit;
};
int main() {
int N, K;
cin >> N >> K;
vector<RestStop> restStops(N);
for (int i = 0; i < N; i++) {
cin >> restStops[i].distance >> restStops[i].profit;
}
// Sorrendezzük a pihenőhelyeket a távolság alapján.
sort(restStops.begin(), restStops.end(), [](const RestStop &a, const RestStop &b) {
return a.distance < b.distance;
});
vector<long long> dp(N);
vector<int> previous(N, -1);
// Dinamikus programozás: dp[i] tárolja a maximális hasznot az i. pihenőhelyig.
for (int i = 0; i < N; i++) {
dp[i] = restStops[i].profit;
for (int j = 0; j < i; j++) {
int distance = restStops[i].distance - restStops[j].distance;
if (distance >= K) {
dp[i] = max(dp[i], dp[j] + restStops[i].profit);
previous[i] = j;
}
}
}
// Keresés a maximális haszonhoz és az épített benzinkutak helyéhez.
long long maxProfit = *max_element(dp.begin(), dp.end());
int maxIndex = max_element(dp.begin(), dp.end()) - dp.begin();
vector<int> gasStations;
while (maxIndex >= 0) {
gasStations.push_back(maxIndex);
maxIndex = previous[maxIndex];
}
cout << maxProfit << endl;
cout << gasStations.size() << " ";
for (int i = gasStations.size() - 1; i >= 0; i--) {
cout << gasStations[i] + 1 << " "; // +1 mert 1-től indexelünk
}
return 0;
}