题解 | 讨厌鬼进货
讨厌鬼进货
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)
}
}
查看8道真题和解析