Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07d6e67

Browse files
Add files via upload
1 parent c58d3c2 commit 07d6e67

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎Mini-Max Sum.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# 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.
2+
# For example, . Our minimum sum is and our maximum sum is . We would print
3+
# 16 24
4+
# Function Description
5+
# Complete the miniMaxSum function in the editor below. It should print two space-separated integers on one line: the minimum sum and the maximum sum of of elements.
6+
# miniMaxSum has the following parameter(s):
7+
# arr: an array of integers
8+
# Input Format
9+
# A single line of five space-separated integers.
10+
# Constraints
11+
12+
# Output Format
13+
# Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than a 32 bit integer.)
14+
# Sample Input
15+
# 1 2 3 4 5
16+
# Sample Output
17+
# 10 14
18+
# Explanation
19+
# Our initial numbers are , , , , and . We can calculate the following sums using four of the five integers:
20+
# If we sum everything except , our sum is .
21+
# If we sum everything except , our sum is .
22+
# If we sum everything except , our sum is .
23+
# If we sum everything except , our sum is .
24+
# If we sum everything except , our sum is .
25+
# Hints: Beware of integer overflow! Use 64-bit Integer.
26+
# Need help to get started? Try the Solve Me First problem
27+
28+
#!/bin/python3
29+
30+
import math
31+
import os
32+
import random
33+
import re
34+
import sys
35+
36+
# Complete the miniMaxSum function below.
37+
def miniMaxSum(arr):
38+
mins = 0
39+
maxs = 0
40+
l = len(arr)-1
41+
arr.sort()
42+
for i in range(0,len(arr)-1):
43+
mins += arr[i]
44+
45+
while(l!=0):
46+
maxs += arr[l]
47+
l -= 1
48+
49+
print(mins,maxs)
50+
51+
if __name__ == '__main__':
52+
arr = list(map(int, input().rstrip().split()))
53+
54+
miniMaxSum(arr)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /