ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2847
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 scores = make([]int, n)
for i := 0; i < n; i++ {
fmt.Fscanln(reader, &scores[i])
}
var result int
for i := n - 2; i >= 0; i-- {
if scores[i+1] <= scores[i] {
diff := scores[i] - scores[i+1] + 1
result += diff
scores[i] -= diff
}
}
fmt.Fprintln(writer, result)
}
๐จ Python3
# https://www.acmicpc.net/problem/2847
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
scores = [int(sys.stdin.readline()) for _ in range(n)]
result = 0
for i in range(n-2, -1, -1):
if scores[i+1] <= scores[i]:
diff = scores[i] - scores[i+1] + 1
result += diff
scores[i] -= diff
print(result)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 5883๋ฒ / ์์ดํฐ 9S [Go][Python3] (0) | 2021.03.14 |
---|---|
BOJ / 14606๋ฒ / ํผ์ (Small) [Go][Python3] (0) | 2021.03.13 |
BOJ / 15828๋ฒ / Router [Go][Python3] (0) | 2021.03.11 |
BOJ / 17212๋ฒ / ๋ฌ๋๋ผ ํ ๋ผ๋ฅผ ์ํ ๊ตฌ๋งค๋๊ธ ์ง๋ถ ๋์ฐ๋ฏธ [Go][Python3] (0) | 2021.03.10 |
BOJ / 1010๋ฒ / ๋ค๋ฆฌ ๋๊ธฐ [Go][Python3] (0) | 2021.03.09 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ballet
- BOJ
- dfs
- java
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋งฅ๋ถํ๋ก
- Golang
- ๋งฅ๋ถ
- MongoDB
- python3
- ์คํ
- ์๋ฐ
- ์๊ฐ๊ต์ฒด
- dp
- baekjoon
- Algorithm
- ๋ฐ๋
- go
- ๋ชฝ๊ณ ๋๋น
- ์๊ณ ๋ฆฌ์ฆ
- ํ๋ก์ด๋์์ฌ
- ์ด๋ถํ์
- ๋ฐฑ์ค
- ํด์๋งต
- BFS
- ๋ธ๋ฃจํธํฌ์ค
- AWS
- Macbook pro 2012 mid 13
- ํ
- ๋ถํ ์ ๋ณต
- Total
- Today
- Yesterday