#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit (c)) {
if (c == '-') {
f = -1;
}
c = getchar();
}
while (isdigit (c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
struct node{
int x, id;
}a1[N], a2[N];
bool cmp (node x, node y) {
return x.x > y.x;
}
int n, v, ans, sum = -1, cnt1, cnt2, pre1[N], pre2[N];
void solve () {
int t, p;
cin >> n >> v;
for (int i = 1; i <= n; i++) {
cin >> t >> p;
if (t == 1) {
a1[++cnt1] = {p, i};
} else {
a2[++cnt2] = {p, i};
}
}
sort (a1 + 1, a1 + cnt1 + 1, cmp);
sort (a2 + 1, a2 + cnt2 + 1, cmp);
for (int i = 1; i <= cnt1; i++) {
pre1[i] = pre1[i - 1] + a1[i].x;
}
for (int i = 1; i <= cnt2; i++) {
pre2[i] = pre2[i - 1] + a2[i].x;
}
for (int i = 0; i * 2 <= n && i <= cnt2; i++) {
if (v - 2 * i > cnt1) continue;
int now = pre2[i] + pre1[v - 2 * i];
if (sum < now) {
sum = now;
ans = i;
}
}
cout << sum << endl;
for (int i = 1; i <= ans; i++) {
cout << a2[i].id << ' ';
}
for (int i = 1; i <= v - 2 * ans; i++) {
cout << a1[i].id << ' ';
}
}
signed main() {
solve();
return 0;
}
思路没问题,cf提示:wrong answer Truck size limit exceeded