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

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

 

1026๋ฒˆ: ๋ณด๋ฌผ

์ฒซ์งธ ์ค„์— N์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” A์— ์žˆ๋Š” N๊ฐœ์˜ ์ˆ˜๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง€๊ณ , ์…‹์งธ ์ค„์—๋Š” B์— ์žˆ๋Š” ์ˆ˜๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. N์€ 50๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๊ณ , A์™€ B์˜ ๊ฐ ์›์†Œ๋Š” 100๋ณด๋‹ค ์ž‘๊ฑฐ

www.acmicpc.net


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

๐ŸŽจ 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
๋Œ“๊ธ€