ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1026
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 a = make([]int, n)
var b = make([]int, n)
for i := 0; i < n; i++ {
fmt.Fscanf(reader, "%d ", &a[i])
}
for i := 0; i < n; i++ {
fmt.Fscanf(reader, "%d ", &b[i])
}
sort.Ints(a)
sort.Slice(b, func(i, j int) bool {
return b[i] > b[j]
})
var result int
for i := 0; i < n; i++ {
result += a[i] * b[i]
}
fmt.Fprintln(writer, result)
}
๐จ Python3
# https://www.acmicpc.net/problem/1026
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
a.sort()
b.sort(reverse=True)
result = 0
for i in range(n):
result += a[i]*b[i]
print(result)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 9184๋ฒ / ์ ๋๋ ํจ์ ์คํ [Go][Python3] (0) | 2021.03.05 |
---|---|
BOJ / 1292๋ฒ / ์ฝ๊ฒ ํธ๋ ๋ฌธ์ [Go][Python3] (0) | 2021.03.04 |
BOJ / 13305๋ฒ / ์ฃผ์ ์ [Go][Python3] (0) | 2021.03.02 |
BOJ / 4796๋ฒ / ์บ ํ [Go][Python3] (0) | 2021.03.01 |
BOJ / 16165๋ฒ / ๊ฑธ๊ทธ๋ฃน ๋ง์คํฐ ์ค์์ด [Go][Python3] (0) | 2021.02.28 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- AWS
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋ธ๋ฃจํธํฌ์ค
- ์๋ฐ
- ๋ฐฑ์ค
- ๋ชฝ๊ณ ๋๋น
- Golang
- ์ด๋ถํ์
- Algorithm
- dfs
- ์คํ
- ํ๋ก์ด๋์์ฌ
- ์๊ฐ๊ต์ฒด
- BFS
- ์๊ณ ๋ฆฌ์ฆ
- ๋งฅ๋ถ
- ๋ฐ๋
- Macbook pro 2012 mid 13
- ballet
- python3
- ํ
- ๋ถํ ์ ๋ณต
- BOJ
- MongoDB
- ๋งฅ๋ถํ๋ก
- baekjoon
- dp
- go
- java
- ํด์๋งต
- Total
- Today
- Yesterday