#include<bits/stdc++.h>
const int N=1e4+5;
using namespace std;
int m,n;
int p[N];
int c[N];
int dp[N][N];
int Trace[N][N];
vector<int>t;
void sol(){
memset(dp,-0x3f,sizeof dp);
dp[0][0]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){
dp[i][j]=dp[i-1][j];
if(j>=c[i]){
dp[i][j]=max(dp[i][j],dp[i-1][j-c[i]]+p[i]);
}
}
}
int ans=0;
int j_toi_uu;
for(int j=0;j<=m;j++){
ans=max(ans,dp[n][j]);
if(ans==dp[n][j]){
j_toi_uu=j;
}
}
cout << ans << '\n';
int i=n,j=j_toi_uu;
while(i > 0){
if(dp[i][j]==dp[i-1][j])i--;
else{
cout << i << ' ';
i--;
j-=c[i];
}
}
cout << '\n';
cout<<j_toi_uu<<"\n";
//return 0;
}
main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>c[i]>>p[i];
}
sol();
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KY29uc3QgaW50IE49MWU0KzU7IAp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbSxuOwppbnQgcFtOXTsKaW50IGNbTl07CmludCBkcFtOXVtOXTsKaW50IFRyYWNlW05dW05dOwp2ZWN0b3I8aW50PnQ7Cgp2b2lkIHNvbCgpewogIG1lbXNldChkcCwtMHgzZixzaXplb2YgZHApOwogIGRwWzBdWzBdPTA7CiAgZm9yKGludCBpPTE7aTw9bjtpKyspewoJIGZvcihpbnQgaj0wO2o8PW07aisrKXsKCQlkcFtpXVtqXT1kcFtpLTFdW2pdOwoJCSBpZihqPj1jW2ldKXsKCQkJZHBbaV1bal09bWF4KGRwW2ldW2pdLGRwW2ktMV1bai1jW2ldXStwW2ldKTsKCQkgfQoJIH0KIH0KIGludCBhbnM9MDsKIGludCBqX3RvaV91dTsKIGZvcihpbnQgaj0wO2o8PW07aisrKXsKIAkgYW5zPW1heChhbnMsZHBbbl1bal0pOwoJIGlmKGFucz09ZHBbbl1bal0pewoJ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