結果

問題 No.2093 Shio Ramen
ユーザー HimaHima
提出日時 2022-10-09 14:19:05
言語 Go
(1.22.1)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,236 bytes
コンパイル時間 12,696 ms
コンパイル使用メモリ 209,288 KB
実行使用メモリ 12,168 KB
最終ジャッジ日時 2023-09-05 18:38:05
合計ジャッジ時間 14,532 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 3 ms
5,560 KB
testcase_10 AC 6 ms
9,916 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
5,556 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
5,552 KB
testcase_15 AC 4 ms
7,856 KB
testcase_16 AC 3 ms
5,560 KB
testcase_17 AC 3 ms
5,564 KB
testcase_18 AC 8 ms
12,164 KB
testcase_19 AC 6 ms
9,924 KB
testcase_20 AC 4 ms
7,848 KB
testcase_21 AC 5 ms
7,896 KB
testcase_22 AC 5 ms
7,832 KB
testcase_23 AC 8 ms
12,164 KB
testcase_24 AC 8 ms
12,164 KB
testcase_25 AC 8 ms
12,164 KB
testcase_26 AC 8 ms
12,164 KB
testcase_27 AC 8 ms
12,168 KB
testcase_28 AC 8 ms
12,164 KB
testcase_29 AC 8 ms
12,168 KB
testcase_30 AC 8 ms
12,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n, li := nextInt(), nextInt()
	var s, a []int
	for i := 0; i < n; i++ {
		s = append(s, nextInt())
		a = append(a, nextInt())
	}
	ans := solve(n, li, s, a)
	PrintInt(ans)
}

func solve(n, li int, s, a []int) int {
	//i杯目のラーメンまで見て、トータルの塩の濃さがjで食べられる味の濃さの最大値
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, li+1)
	}
	for i := 1; i <= n; i++ {
		for j := 0; j <= li; j++ {
			//i杯目のラーメンを食べない
			dp[i][j] = dp[i-1][j]
			//i杯目のラーメンを食べる
			nextS := j + s[i-1]
			if nextS > li {
				continue
			}
			dp[i][j] = Max(dp[i][j], dp[i-1][nextS]+a[i-1])
		}
	}
	var ans int
	for j := 0; j <= li; j++ {
		ans = Max(ans, dp[n][j])
	}
	return ans
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func PrintInt(x int) {
	defer out.Flush()
	fmt.Fprintln(out, x)
}

func Max(x, y int) int {
	if x < y {
		return y
	}
	return x
}
0