← Home
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type Vehicle struct {
	p  int
	id int
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, v int
	fmt.Fscan(reader, &n, &v)

	var type1, type2 []Vehicle

	for i := 1; i <= n; i++ {
		var t, p int
		fmt.Fscan(reader, &t, &p)
		if t == 1 {
			type1 = append(type1, Vehicle{p, i})
		} else {
			type2 = append(type2, Vehicle{p, i})
		}
	}

	sort.Slice(type1, func(i, j int) bool {
		return type1[i].p > type1[j].p
	})
	sort.Slice(type2, func(i, j int) bool {
		return type2[i].p > type2[j].p
	})

	pref1 := make([]int64, len(type1)+1)
	for i := 0; i < len(type1); i++ {
		pref1[i+1] = pref1[i] + int64(type1[i].p)
	}

	pref2 := make([]int64, len(type2)+1)
	for i := 0; i < len(type2); i++ {
		pref2[i+1] = pref2[i] + int64(type2[i].p)
	}

	var maxCap int64 = -1
	var bestC, bestK int

	for i := 0; i <= len(type2); i++ {
		if int64(i)*2 > int64(v) {
			break
		}
		remV := v - i*2
		k := remV
		if k > len(type1) {
			k = len(type1)
		}
		curCap := pref2[i] + pref1[k]
		if curCap > maxCap {
			maxCap = curCap
			bestC = i
			bestK = k
		}
	}

	fmt.Println(maxCap)
	for i := 0; i < bestC; i++ {
		fmt.Printf("%d ", type2[i].id)
	}
	for i := 0; i < bestK; i++ {
		fmt.Printf("%d ", type1[i].id)
	}
	fmt.Println()
}