From 82459aba37b7664753f2b8963b261d3096fdb0b0 Mon Sep 17 00:00:00 2001 From: Minsung_Kang Date: Tue, 2 Apr 2024 17:46:13 +0900 Subject: [PATCH] =?UTF-8?q?2024-04-02=20=EB=91=90=20=EC=9A=A9=EC=95=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rivkms/README.md | 4 +++- rivkms/Two_pointer/2470.cpp | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 rivkms/Two_pointer/2470.cpp diff --git a/rivkms/README.md b/rivkms/README.md index 24b6cef..5c1bf5b 100644 --- a/rivkms/README.md +++ b/rivkms/README.md @@ -10,4 +10,6 @@ | 6차시 | 2024.02.27 | BFS | [토마토](https://www.acmicpc.net/problem/7576) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/20) | | 7차시 | 2024.03.01 | DP | [연속합](https://www.acmicpc.net/problem/1912) | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/25) | | 8차시 | 2024.03.01 | Greedy | [회의실 배정](https://www.acmicpc.net/problem/1931) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/28) | -| 9차시 | 2024.03.22 | two-pointer | [두 수의 합](https://www.acmicpc.net/problem/3273) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/38) | \ No newline at end of file +| 9차시 | 2024.03.22 | two-pointer | [두 수의 합](https://www.acmicpc.net/problem/3273) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/38) | +| 10차시 | 2024.03.28 | queue | [최대힙](https://www.acmicpc.net/problem/11279) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/40) | +| 11차시 | 2024.04.02 | two-pointer | [두 용액](https://www.acmicpc.net/problem/2470) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/45) | \ No newline at end of file diff --git a/rivkms/Two_pointer/2470.cpp b/rivkms/Two_pointer/2470.cpp new file mode 100644 index 0000000..49ec015 --- /dev/null +++ b/rivkms/Two_pointer/2470.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +using namespace std; + +int main(){ + int n; + cin >> n; + vector vec(n,0); + for(int i = 0; i> vec[i]; + } + sort(vec.begin(), vec.end()); + vector answer(2); + int p1 = 0, p2 = n-1; + int min = INT32_MAX; + while(true){ + if(p1 >= p2){ + break; + } + int sum = vec[p1]+vec[p2]; + if(abs(sum) < min){ + min = abs(sum); + answer[0] = vec[p1]; + answer[1] = vec[p2]; + if(sum == 0){ + break; + } + } + if(sum < 0){ + p1++; + } + else{ + p2--; + } + } + cout << answer[0] << " " << answer[1]; + return 0; +} \ No newline at end of file