ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2217
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var ropes = make([]int, n)
for i := 0; i < n; i++ {
fmt.Fscanln(reader, &ropes[i])
}
sort.Ints(ropes)
var maxWeight int
for i := len(ropes) - 1; i >= 0; i-- {
weight := ropes[i] * (len(ropes) - i)
if weight > maxWeight {
maxWeight = weight
}
}
fmt.Fprintln(writer, maxWeight)
}
๐จ Python3
# https://www.acmicpc.net/problem/2217
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
ropes = []
for i in range(n):
ropes.append(int(sys.stdin.readline()))
ropes.sort()
max_weight = 0
for i in reversed(range(len(ropes))):
weight = ropes[i] * (len(ropes) - i)
max_weight = max(max_weight, weight)
print(max_weight)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1543๋ฒ / ๋ฌธ์ ๊ฒ์ [Go][Python3] (0) | 2021.02.11 |
---|---|
BOJ / 1485๋ฒ / ์ ์ฌ๊ฐํ [Go][Python3] (0) | 2021.02.10 |
BOJ / 4659๋ฒ / ๋น๋ฐ๋ฒํธ ๋ฐ์ํ๊ธฐ [Go][Python3] (0) | 2021.02.08 |
BOJ / 11656๋ฒ / ์ ๋ฏธ์ฌ ๋ฐฐ์ด [Go][Python3] (0) | 2021.02.07 |
BOJ / 10799๋ฒ / ์ ๋ง๋๊ธฐ [Go][Python3] (0) | 2021.02.06 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ์๊ณ ๋ฆฌ์ฆ
- ๋งฅ๋ถํ๋ก
- ํ
- go
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์๊ฐ๊ต์ฒด
- Golang
- Algorithm
- dfs
- ๋ถํ ์ ๋ณต
- ๋ธ๋ฃจํธํฌ์ค
- ๋ชฝ๊ณ ๋๋น
- baekjoon
- AWS
- BOJ
- Macbook pro 2012 mid 13
- BFS
- dp
- ๋งฅ๋ถ
- python3
- ํ๋ก์ด๋์์ฌ
- ๋ฐ๋
- ์ด๋ถํ์
- java
- ๋ฐฑ์ค
- ํด์๋งต
- ์๋ฐ
- ์คํ
- MongoDB
- ballet
- Total
- Today
- Yesterday