CSES - Aalto Competitive Programming 2024 - wk1 - Mon - Results
Submission details
Task:Backpacking
Sender:clovis
Submission time:2024-09-02 16:35:22 +0300
Language:CPython3
Status:READY
Result:
Test results
testverdicttime
#10.02 sdetails
#20.02 sdetails
#30.02 sdetails
#40.02 sdetails

Code

# Teemu is going backpacking. His mom has given him two types of fruits, apples and bananas. As Teemu's stomach doesn't distinguish between them, each apple or banana gives him one hour of energy for backpacking. Given that his mom gave him A apples and B bananas, calculate how many hours Teemu can backpack if he doesn't have any other source of energy.
# Input
# The first line of input consists of two space-separated numbers, A and B.
# Output
# Output a single integer O, number of hours before Teemu is out of energy. 
# Constraints

# 0 \le A,B \le 10^6

# Example
# Input:
# 3 5

# Output:
# 8

# problem: given a string separated by spaces with 2 numbers, add them the 2 numbers up and output the sum

# approach
# split the string by space
# iterate through the list
# sum up

def sum_energy(s):
  fruitList = s.split(" ")

  totalEnergy = 0
  for fruit in fruitList:
    totalEnergy += int(fruit)
  
  return totalEnergy

if __name__ == "__main__":
  sum_energy(s)

Test details

Test 1

Verdict:

input
3 5

correct output
8

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 34, in <module>
    sum_energy(s)
NameError: name 's' is not defined

Test 2

Verdict:

input
571335 750047

correct output
1321382

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 34, in <module>
    sum_energy(s)
NameError: name 's' is not defined

Test 3

Verdict:

input
744471 719178

correct output
1463649

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 34, in <module>
    sum_energy(s)
NameError: name 's' is not defined

Test 4

Verdict:

input
308833 436123

correct output
744956

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 34, in <module>
    sum_energy(s)
NameError: name 's' is not defined