ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

1049๋ฒˆ: ๊ธฐํƒ€์ค„

์ฒซ์งธ ์ค„์— N๊ณผ M์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 100๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , M์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ M๊ฐœ์˜ ์ค„์—๋Š” ๊ฐ ๋ธŒ๋žœ๋“œ์˜ ํŒจํ‚ค์ง€ ๊ฐ€๊ฒฉ๊ณผ ๋‚ฑ๊ฐœ์˜ ๊ฐ€๊ฒฉ์ด ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ฃผ

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

// https://www.acmicpc.net/problem/1049
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, m int
	fmt.Fscanln(reader, &n, &m)

	var minPackage, minSingle = 1000, 1000
	for i := 0; i < m; i++ {
		var packagePrice, singlePrice int
		fmt.Fscanln(reader, &packagePrice, &singlePrice)
		if minPackage > packagePrice {
			minPackage = packagePrice
		}
		if minSingle > singlePrice {
			minSingle = singlePrice
		}
	}
	var money int
	if minSingle*6 > minPackage {
		money += (n / 6) * minPackage
		n %= 6
		if n > 0 {
			if minSingle*n > minPackage {
				money += minPackage
			} else {
				money += minSingle * n
			}
		}
	} else {
		money += n * minSingle
	}

	fmt.Fprintln(writer, money)
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/1049
import sys

if __name__ == "__main__":
    n, m = list(map(int, sys.stdin.readline().split()))
    min_package, min_single = 1000, 1000
    for i in range(m):
        package_price, single_price = list(map(int, sys.stdin.readline().split()))
        min_package = min(min_package, package_price)
        min_single = min(min_single, single_price)
    money = 0
    if min_single*6 > min_package:
        money += (n // 6) * min_package
        n %= 6
        if n > 0:
            if min_single * n > min_package:
                money += min_package
            else:
                money += min_single*n
    else:
        money += n * min_single
    print(money)
728x90
๋Œ“๊ธ€