Language: C++

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	n, w := readInt2()
	wvs := make([][]int, n)
	for i := range wvs {
		tmpw, tmpv := readInt2()
		wvs[i] = []int{tmpw, tmpv}
	}

	dp := make([][]int, n)
	for i := range dp {
		dp[i] = make([]int, w+1)
	}

	for i := 0; i < n; i++ {
		for weight := 0; weight <= w; weight++ {
			iw, iv := wvs[i][0], wvs[i][1]
			var sel int
			// 選ぶ場合の価値を計算する
			if iw <= weight {
				if i == 0 {
					sel = iv
				} else {
					// i 番目が入ってくる前で、i の重さを除いた時の一番価値が高い状態に足し合せる
					sel = dp[i-1][weight-iw] + iv
				}
			}
			// 選ばない場合は一個前の価値を引き継ぐ
			var nosel int
			if i == 0 {
				nosel = 0
			} else {
				nosel = dp[i-1][weight]
			}

			//fmt.Printf("i: %d, w: %d, sel: %d, nosel: %d\n", i, weight, sel, nosel)
			dp[i][weight] = max(sel, nosel)
		}
	}

	fmt.Println(dp[n-1][w])
}


Compiler output:
a.cc:1:1: error: 'package' does not name a type
    1 | package main
      | ^~~~~~~
a.cc:19:1: error: 'func' does not name a type
   19 | func readInt() int              { return readIntArray(1)[0] }
      | ^~~~
a.cc:20:1: error: 'func' does not name a type
   20 | func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
      | ^~~~
a.cc:21:1: error: 'func' does not name a type
   21 | func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
      | ^~~~
a.cc:22:1: error: 'func' does not name a type
   22 | func readIntArray(n int) []int {
      | ^~~~
a.cc:30:1: error: 'func' does not name a type
   30 | func readString() string            { return readStringArray(1)[0] }
      | ^~~~
a.cc:31:1: error: 'func' does not name a type
   31 | func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
      | ^~~~
a.cc:32:1: error: 'func' does not name a type
   32 | func readStringArray(n int) []string {
      | ^~~~
a.cc:40:1: error: 'func' does not name a type
   40 | func max(ns ...int) int {
      | ^~~~
a.cc:49:1: error: 'func' does not name a type
   49 | func min(ns ...int) int {
      | ^~~~
a.cc:58:1: error: 'func' does not name a type
   58 | func abs(x int) int {
      | ^~~~
a.cc:65:1: error: 'func' does not name a type
   65 | func main() {
      | ^~~~