-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sys | ||
|
||
|
||
def solve(): | ||
input = sys.stdin.readline | ||
N = int(input().strip()) | ||
dts = list(map(int, input().strip().split())) | ||
dts.sort() | ||
|
||
MAX = 1000000000 + 1 | ||
answers = [MAX, MAX, MAX] | ||
|
||
# mid를 반드시 포함하는 3개의 용액을 찾는다. | ||
for mid in range(1, N - 1): | ||
left, right = mid - 1, mid + 1 | ||
|
||
while left < mid < right and 0 <= left and right < N: | ||
if abs(dts[left] + dts[mid] + dts[right]) < abs(sum(answers)): | ||
answers[0], answers[1], answers[2] = dts[left], dts[mid], dts[right] | ||
|
||
if dts[left] + dts[mid] + dts[right] < 0: | ||
right += 1 | ||
elif dts[left] + dts[mid] + dts[right] > 0: | ||
left -= 1 | ||
else: | ||
print(' '.join(map(str, answers))) | ||
return | ||
|
||
print(' '.join(map(str, answers))) | ||
|
||
|
||
if __name__ == '__main__': | ||
solve() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
5 | ||
-2 6 -97 -6 98 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-97 -2 98 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
7 | ||
-2 -3 -24 -6 98 100 61 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-6 -3 -2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sys | ||
from pathlib import Path | ||
from unittest import TestCase | ||
from main import solve | ||
|
||
|
||
class Test(TestCase): | ||
def my_solve(self, testcase_input): | ||
sys.stdin = open(testcase_input, 'r') | ||
stdout = sys.stdout | ||
sys.stdout = open('stdout.txt', 'w') | ||
solve() | ||
sys.stdout.close() | ||
sys.stdout = stdout | ||
|
||
def test_solve(self, testcase_number: str): | ||
self.my_solve('test' + testcase_number + '.txt') | ||
self.assertEqual( | ||
Path('test' + testcase_number + '_answer.txt').read_text().strip(), | ||
Path('stdout.txt').read_text().strip()) | ||
|
||
def test1_solve(self): | ||
self.test_solve('1') | ||
|
||
def test2_solve(self): | ||
self.test_solve('2') |