ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/13305
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var distances = make([]int, n-1)
var prices = make([]int, n)
for i := 0; i < n-1; i++ {
fmt.Fscanf(reader, "%d ", &distances[i])
}
for i := 0; i < n; i++ {
fmt.Fscanf(reader, "%d ", &prices[i])
}
result := 0
for i := 0; i < n-1; i++ {
cur := prices[i]
dist := distances[i]
for j := i + 1; j < n-1; j++ {
next := prices[j]
if cur < next {
dist += distances[j]
i++
} else {
break
}
}
result += dist * cur
}
fmt.Fprintln(writer, result)
}
๐จ Python3
# https://www.acmicpc.net/problem/13305
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
distances = list(map(int, sys.stdin.readline().split()))
prices = list(map(int, sys.stdin.readline().split()))
result = 0
i = 0
while i < n-1:
cur = prices[i]
dist = distances[i]
for j in range(i+1, n-1):
next = prices[j]
if cur < next:
dist += distances[j]
i += 1
else:
break
result += dist * cur
i += 1
print(result)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1292๋ฒ / ์ฝ๊ฒ ํธ๋ ๋ฌธ์ [Go][Python3] (0) | 2021.03.04 |
---|---|
BOJ / 1026๋ฒ / ๋ณด๋ฌผ [Go][Python3] (0) | 2021.03.03 |
BOJ / 4796๋ฒ / ์บ ํ [Go][Python3] (0) | 2021.03.01 |
BOJ / 16165๋ฒ / ๊ฑธ๊ทธ๋ฃน ๋ง์คํฐ ์ค์์ด [Go][Python3] (0) | 2021.02.28 |
BOJ / 11478๋ฒ / ์๋ก ๋ค๋ฅธ ๋ถ๋ถ ๋ฌธ์์ด์ ๊ฐ์ [Go][Python3] (0) | 2021.02.27 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ํ๋ก์ด๋์์ฌ
- ๋ถํ ์ ๋ณต
- ํด์๋งต
- ballet
- ๋ฐ๋
- dfs
- ์๋ฐ
- MongoDB
- BOJ
- ์๊ณ ๋ฆฌ์ฆ
- Algorithm
- baekjoon
- ๋ฐฑ์ค
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- Golang
- ์๊ฐ๊ต์ฒด
- ์คํ
- dp
- Macbook pro 2012 mid 13
- ๋ธ๋ฃจํธํฌ์ค
- AWS
- ๋งฅ๋ถ
- ์ด๋ถํ์
- go
- ๋ชฝ๊ณ ๋๋น
- ํ
- python3
- BFS
- java
- ๋งฅ๋ถํ๋ก
- Total
- Today
- Yesterday