Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.
5개의 element를 가진 array를 받아서 그 중에서 4개를 더하는 데 그 더한 값 중 가장 큰 값과 가장 작은 값을 구하면 된다. Sort를 한 다음에, 가장 앞의 값 (가장 작은 값) 을 빼고 더해서 -> Max 가장 뒤에 값 (가장 큰 값)을 빼고 더해서 -> Min을 구했다.
비교적 쉽게 풀렸던 문제. python에는 다양한 내장 함수들이 있어서 코딩할 때 참 편하다 ㅎㅎ
# Solution 1
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'miniMaxSum' function below.
#
# The function accepts INTEGER_ARRAY arr as parameter.
#
def miniMaxSum(arr):
# Write your code here
arr = sorted(arr)
min = 0
max = 0
for i in arr[1:]:
max+=i
for i in arr[:-1]:
min+=i
print(min, max)
return min, max
if __name__ == '__main__':
arr = list(map(int, input().rstrip().split()))
miniMaxSum(arr)