package main import ( "bufio" "fmt" "os" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 1 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) cnt = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() for i := 0; i < cnt; i++ { if i > 0 { fmt.Fprintln(writer, "-----------------------------------") } solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) c := getNextInt(scanner) bb := make([]bamboo, n) for i := 0; i < n; i++ { bb[i].l = getNextInt(scanner) } for i := 0; i < n; i++ { bb[i].w = getNextInt(scanner) } var dp [51][51][51]int for i := 0; i < n; i++ { for j := 0; j < n; j++ { if bb[i].l == bb[j].l { continue } if bb[i].w+bb[j].w > c { continue } dp[bb[i].l][bb[j].l][bb[i].w+bb[j].w] = bb[i].l + bb[j].l } } updated := true var ans int for updated == true { updated = false for i := 0; i < n; i++ { for j := 0; j < bb[i].l; j++ { for k := j + 1; k < 51; k++ { for l := 0; l+bb[i].w <= c; l++ { if dp[j][k][l] == 0 { continue } if k == bb[i].l { continue } if dp[bb[i].l][j][l+bb[i].w] < dp[j][k][l]+bb[i].l { dp[bb[i].l][j][l+bb[i].w] = dp[j][k][l] + bb[i].l if ans < dp[bb[i].l][j][l+bb[i].w] { ans = dp[bb[i].l][j][l+bb[i].w] } updated = true } } } } for j := bb[i].l + 1; j < 51; j++ { for k := 0; k < j; k++ { for l := 0; l+bb[i].w <= c; l++ { if dp[j][k][l] == 0 { continue } if k == bb[i].l { continue } if dp[bb[i].l][j][l+bb[i].w] < dp[j][k][l]+bb[i].l { dp[bb[i].l][j][l+bb[i].w] = dp[j][k][l] + bb[i].l if ans < dp[bb[i].l][j][l+bb[i].w] { ans = dp[bb[i].l][j][l+bb[i].w] } updated = true } } } } } } fmt.Fprintln(writer, ans) } type bamboo struct { l, w int }