You are viewing a single comment's thread. Return to all comments →
Thanks for all of your hardwork on this site; however, the Golang test arrays are broken. Here is a rough fix but could be refactored to HR's liking.
func main() { reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
stdout, err := os.Create(os.Getenv("OUTPUT_PATH")) checkError(err) defer stdout.Close() caseSize, _, err := reader.ReadLine() checkError(err) cases := strings.Split(string(caseSize), "") writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024) limit, err := strconv.ParseInt(cases[0], 10, 64) for limit > 0 { unread, _, err := reader.ReadLine() checkError(err) read := strings.Split(string(unread), " ") nTemp, err := strconv.ParseInt(read[0], 10, 64) checkError(err) n := int32(nTemp) kTemp, err := strconv.ParseInt(read[1], 10, 64) checkError(err) k := int32(kTemp) arrUnread, _, err := reader.ReadLine() checkError(err) arrRead := strings.Split(string(arrUnread), " ") var arr []int32 for i := 0; i < int(n); i++ { arrItemTemp, err := strconv.ParseInt(arrRead[i], 10, 64) checkError(err) arrItem := int32(arrItemTemp) arr = append(arr, arrItem) } result := unboundedKnapsack(k, arr) fmt.Fprintf(writer, "%d\n", result) writer.Flush() limit-- } return
}
Seems like cookies are disabled on this browser, please enable them to open this website
Knapsack
You are viewing a single comment's thread. Return to all comments →
Thanks for all of your hardwork on this site; however, the Golang test arrays are broken. Here is a rough fix but could be refactored to HR's liking.
func main() { reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
}