Skip to content

Commit

Permalink
2024-04-20 16:19:12
Browse files Browse the repository at this point in the history
Affected files:
src/content/blog/boj-1026-보물.md
  • Loading branch information
gyunseo committed Apr 20, 2024
1 parent c39dec6 commit 17fbb8c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/content/blog/boj-1026-보물.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,32 @@ ogImage: ""
![](https://res.cloudinary.com/gyunseo-blog/image/upload/f_auto/v1713597185/image_mrqq0q.png)
결국 `A` 배열은 `B`의 계수로 볼 수 있습니다.
그래서 `B`배열의 원소들은 재배열 제약으로부터 자유로워지고, 그냥 `A``B` 각각 내림차순, 오름차순으로 정렬해서, 각 원소를 곱한 값을 구하면 됩니다.

## AC 받은 Python 코드

```python
import sys

input = sys.stdin.readline
MAX_LEN = 50
MAX_VAL = 100


def get_S():
ret = 0
for i in range(N):
ret += A[i] * B[i]
return ret


if __name__ == "__main__":
N = int(input().rstrip())
A = [*map(int, input().rstrip().split())]
B = [*map(int, input().rstrip().split())]
# print("A: ", A)
# print("B: ", B)
# A가 B의 계수라고 생각하면 된다
A.sort(key=lambda x: -x)
B.sort()
print(get_S())
```

0 comments on commit 17fbb8c

Please sign in to comment.