CSES - E4590 2019 0 - Results
 Task: 3-sum Sender: Christabella Irwanto Submission time: 2019-09-12 16:25:13 +0300 Language: CPython3 Status: READY Result: ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.02 sdetails
#3ACCEPTED0.02 sdetails
#4ACCEPTED0.02 sdetails
#5ACCEPTED0.02 sdetails
#6ACCEPTED0.02 sdetails
#7ACCEPTED0.02 sdetails
#8ACCEPTED0.02 sdetails
#9ACCEPTED0.02 sdetails
#10ACCEPTED0.02 sdetails
#11ACCEPTED0.02 sdetails
#12ACCEPTED0.02 sdetails
#13ACCEPTED0.02 sdetails
#14ACCEPTED0.02 sdetails
#15ACCEPTED0.02 sdetails
#16ACCEPTED0.02 sdetails
#17ACCEPTED0.02 sdetails
#18ACCEPTED0.02 sdetails
#19ACCEPTED0.02 sdetails
#20ACCEPTED0.02 sdetails
#21ACCEPTED0.02 sdetails
#22ACCEPTED0.02 sdetails
#23ACCEPTED0.02 sdetails
#24ACCEPTED0.02 sdetails
#25ACCEPTED0.02 sdetails
#26ACCEPTED0.02 sdetails
#27ACCEPTED0.02 sdetails
#28ACCEPTED0.02 sdetails

### Code

```#!/usr/bin/env python

"""
time: O(n logn)
space: O(1) if sort is in-place

2. keep a max heap and return heap pop 3 times
time: O(n) since average insertion of heap is O(1)
"""

from heapq import heappush, heappop

def solve(arr):
"""
You are given n distinct integers. Your task is to select three of them
such that their sum is maximal.
"""
three_sum = []
heap = []
for num in arr:
heappush(heap, -num)
for i in range(3):
three_sum.append(-heappop(heap))
print(' '.join(map(str, three_sum)))

if __name__ == "__main__":
_ = int(input())
arr = [int(x) for x in input().split()]
solve(arr)
```

### Test details

#### Test 1

Verdict: ACCEPTED

input
3
-702 391 288

correct output
-702 391 288

user output
391 288 -702

#### Test 2

Verdict: ACCEPTED

input
3
-609 886 -448

correct output
-609 886 -448

user output
886 -448 -609

#### Test 3

Verdict: ACCEPTED

input
3
484 -459 605

correct output
484 -459 605

user output
605 484 -459

#### Test 4

Verdict: ACCEPTED

input
10
491 934 -395 -873 -822 447 -90...

correct output
491 934 447

user output
934 491 447

#### Test 5

Verdict: ACCEPTED

input
10
-293 853 267 -762 -647 843 35 ...

correct output
853 843 744

user output
853 843 744

#### Test 6

Verdict: ACCEPTED

input
10
-389 -908 441 187 993 -68 -593...

correct output
441 187 993

user output
993 441 187

#### Test 7

Verdict: ACCEPTED

input
4
-195 251 -11 423

correct output
251 -11 423

user output
423 251 -11

#### Test 8

Verdict: ACCEPTED

input
4
-522 -222 -909 294

correct output
-522 -222 294

user output
294 -222 -522

#### Test 9

Verdict: ACCEPTED

input
4
141 764 -262 3

correct output
141 764 3

user output
764 141 3

#### Test 10

Verdict: ACCEPTED

input
5
669 -567 -224 160 194

correct output
669 160 194

user output
669 194 160

#### Test 11

Verdict: ACCEPTED

input
5
294 783 -60 -637 126

correct output
294 783 126

user output
783 294 126

#### Test 12

Verdict: ACCEPTED

input
5
-941 391 -339 -982 808

correct output
391 -339 808

user output
808 391 -339

#### Test 13

Verdict: ACCEPTED

input
11
726 997 -588 -186 465 472 -865...

correct output
726 997 472

user output
997 726 472

#### Test 14

Verdict: ACCEPTED

input
11
-346 950 -522 106 278 265 531 ...

correct output
950 531 678

user output
950 678 531

#### Test 15

Verdict: ACCEPTED

input
11
633 -52 -771 449 409 684 -516 ...

correct output
633 449 684

user output
684 633 449

#### Test 16

Verdict: ACCEPTED

input
57
714 -738 -127 -549 613 11 263 ...

correct output
880 887 947

user output
947 887 880

#### Test 17

Verdict: ACCEPTED

input
57
-599 -338 -960 581 -979 -85 -1...

correct output
830 988 852

user output
988 852 830

#### Test 18

Verdict: ACCEPTED

input
57
-346 -990 -893 -109 876 438 -5...

correct output
876 910 885

user output
910 885 876

#### Test 19

Verdict: ACCEPTED

input
99
621 189 655 890 -48 -440 276 6...

correct output
945 962 994

user output
994 962 945

#### Test 20

Verdict: ACCEPTED

input
99
-617 799 -960 436 725 -177 -30...

correct output
976 930 968

user output
976 968 930

#### Test 21

Verdict: ACCEPTED

input
99
-34 722 -880 -572 -241 415 -28...

correct output
944 893 930

user output
944 930 893

#### Test 22

Verdict: ACCEPTED

input
100
-992 368 517 -516 -307 -813 -3...

correct output
987 983 978

user output
987 983 978

#### Test 23

Verdict: ACCEPTED

input
100
-410 683 -411 -720 -559 -997 4...

correct output
996 997 1000

user output
1000 997 996

#### Test 24

Verdict: ACCEPTED

input
100
42 -652 -295 -94 -213 -974 658...

correct output
960 997 933

user output
997 960 933

#### Test 25

Verdict: ACCEPTED

input
100
230 16 1000 314 599 242 -921 4...

correct output
1000 999 998

user output
1000 999 998

#### Test 26

Verdict: ACCEPTED

input
100
-557 -203 -490 -20 -187 -727 -...

correct output
-20 -12 -6

user output
-6 -12 -20

#### Test 27

Verdict: ACCEPTED

input
100
-857 -525 -888 -592 -468 -378 ...

correct output
-1 -16 -34

user output
-1 -16 -34

#### Test 28

Verdict: ACCEPTED

input
100
-985 -939 -972 -976 -936 -971 ...

correct output
-900 -901 -902

user output
-900 -901 -902