Submission details
Task:Apple Division
Sender:aalto26aw_011
Submission time:2026-09-02 17:09:04 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.06 sdetails
#20.06 sdetails
#30.06 sdetails
#40.06 sdetails
#50.06 sdetails
#60.06 sdetails
#70.06 sdetails
#80.06 sdetails
#90.06 sdetails
#100.06 sdetails
#110.06 sdetails
#120.06 sdetails
#130.04 sdetails
#140.06 sdetails
#150.04 sdetails
#160.06 sdetails
#170.06 sdetails
#180.06 sdetails

Code

def apple_division():
    num_of_apples = input()
    num_of_apples = int(num_of_apples)

    i = 0
    apple_weights = []
    while i < num_of_apples:
        apple_weight = input()
        apple_weight = int(apple_weight)
        apple_weights.append(apple_weight)
        i += 1

    apple_weights = sorted(apple_weights)

    left_group_weight = 0
    right_group_weight = 0

    li = len(apple_weights) - 2
    ri = len(apple_weights) - 1

    while li >= 0 and ri >= 0:
        right_group_weight = right_group_weight + apple_weights[ri]

        while left_group_weight < right_group_weight:
            left_group_weight = left_group_weight + apple_weights[li]
            li = li - 1

            if li < 0:
                break

        ri = li - 1


    difference = left_group_weight - right_group_weight

    if difference < 0:
        difference = difference * -1

    print(difference)

    return
    

if __name__ == "__main__":
    apple_division()



"""
Primer intento

while ri > li:
        right_group_weight = right_group_weight + apple_weights[ri]
        ri = ri - 1
        
        while left_group_weight < right_group_weight:
            left_group_weight = left_group_weight + apple_weights[li]
            li = li + 1
"""

Test details

Test 1

Verdict:

input
10
603 324 573 493 659 521 654 70...

correct output
2

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '603 324 573 493 659 521 654 70 718 257'

Test 2

Verdict:

input
10
952 775 292 702 859 719 65 943...

correct output
1

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '952 775 292 702 859 719 65 943 376 490'

Test 3

Verdict:

input
10
141 156 14 487 250 230 741 602...

correct output
2

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '141 156 14 487 250 230 741 602 32 717'

Test 4

Verdict:

input
10
963 359 731 826 599 931 40 86 ...

correct output
4

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '963 359 731 826 599 931 40 86 777 760'

Test 5

Verdict:

input
10
238 224 861 461 558 860 318 93...

correct output
2

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '238 224 861 461 558 860 318 93 347 402'

Test 6

Verdict:

input
10
193 848 70 53 864 886 374 31 2...

correct output
1

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '193 848 70 53 864 886 374 31 288 700'

Test 7

Verdict:

input
20
13048212 423374770 19874608 81...

correct output
8231

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '13048212 423374770 19874608 812293014 860896267 224937483 907570920 952166494 450127366 887381168 966393898 102318919 723213664 491414754 571209206 99007249 302987622 263275846 36174214 727737543'

Test 8

Verdict:

input
20
314836307 815098885 922742346 ...

correct output
1188

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '314836307 815098885 922742346 53006071 757943472 481505203 354207278 175676232 335088325 921705085 231986392 619406418 170606376 498080884 415616625 40905556 110076295 642911923 932231564 381545587'

Test 9

Verdict:

input
20
846261131 196958704 824235264 ...

correct output
11770

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '846261131 196958704 824235264 647587496 978085759 882269655 811438806 657727455 24328597 474430888 447727984 21699367 842686077 330551298 93526006 720473844 163948377 592752691 429743319 68287836'

Test 10

Verdict:

input
20
92021619 792314463 937735495 8...

correct output
4453

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '92021619 792314463 937735495 807418830 589829609 270804901 94470968 853138862 817966179 656206734 121829906 137518261 766263169 320158086 167044551 860185204 347066817 401533984 755773385 623993044'

Test 11

Verdict:

input
20
452747515 202201476 845758891 ...

correct output
4881

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '452747515 202201476 845758891 733204504 327861300 368456549 64252070 494676885 21095634 611030397 913689714 849191653 173901982 954566440 40404105 228316310 210730656 631709598 847867437 85805975'

Test 12

Verdict:

input
20
934033764 747013925 113297529 ...

correct output
5482

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '934033764 747013925 113297529 621350044 4858224 896418401 823418019 490285020 811592918 318107753 122431099 971962557 68572395 269437889 506050802 903504371 908615271 406858603 39392057 816479349'

Test 13

Verdict:

input
1
1000000000

correct output
1000000000

user output
0

Feedback: Incorrect character on line 1 col 1: expected "1000000000", got "0"

Test 14

Verdict:

input
2
1 1

correct output
0

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '1 1'

Test 15

Verdict:

input
1
1

correct output
1

user output
0

Feedback: Incorrect character on line 1 col 1: expected "1", got "0"

Test 16

Verdict:

input
5
934033764 2 7 4 1

correct output
934033750

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '934033764 2 7 4 1'

Test 17

Verdict:

input
20
934033764 747013925 113297529 ...

correct output
5483

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '934033764 747013925 113297529 621350044 4858224 896418401 823418019 490285020 811592918 318107753 122431099 971962557 68572395 269437889 506050802 903504371 908615271 406858603 39392057 816479348'

Test 18

Verdict:

input
19
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1

user output
(empty)

Error:
Traceback (most recent call last):
  File "/box/input/code.py", line 45, in <module>
    apple_division()
  File "/box/input/code.py", line 9, in apple_division
    apple_weight = int(apple_weight)
ValueError: invalid literal for int() with base 10: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'