题解 | 讨厌鬼进货

讨厌鬼进货

https://www.nowcoder.com/practice/e364bac751204aa0b2d27389ca8e3c94

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bufSize := 2 * 1024 * 1024
	buf := make([]byte, bufSize)
	sc.Buffer(buf, bufSize)
	sc.Scan()
	nx := strings.Split(sc.Text(), " ")
	n, _ := strconv.Atoi(nx[0])
	x, _ := strconv.Atoi(nx[1])
	sc.Scan()
	a := strings.Split(sc.Text(), " ")
	sc.Scan()
	b := strings.Split(sc.Text(), " ")
	total := 0
	for i := 0; i < n; i++ {
		ac, _ := strconv.Atoi(a[i])
		bc, _ := strconv.Atoi(b[i])
		if ac <= bc {
			total += ac
		} else {
			total += bc
		}
	}
	if total <= x {
		fmt.Print(total)
	} else {
		fmt.Print(x)
	}
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务