Skip to content

Commit

Permalink
Merge pull request #48 from AlgoLeadMe/14-kangrae-jo
Browse files Browse the repository at this point in the history
14-kangrae-jo
  • Loading branch information
kangrae-jo authored Jan 19, 2025
2 parents 585d95b + 4d346d6 commit f001e97
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions kangrae-jo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
| 11์ฐจ์‹œ | 2024.12.21 | Greedy | [ATM](https://www.acmicpc.net/problem/11399)|[#41](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/41)|
| 12์ฐจ์‹œ | 2024.12.24 | HEAP | [ํฌ๋ฆฌ์Šค๋งˆ์Šค ์„ ๋ฌผ](https://www.acmicpc.net/problem/14235)|[#44](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/44)|
| 13์ฐจ์‹œ | 2024.12.28 | Graph | [์ค„ ์„ธ์šฐ๊ธฐ](https://www.acmicpc.net/problem/2252)|[#46](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/46)|
| 14์ฐจ์‹œ | 2024.12.31 | Two Pointer | [๋‘ ์šฉ์•ก](https://www.acmicpc.net/problem/2470)|[#48](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/48)|

---
40 changes: 40 additions & 0 deletions kangrae-jo/Two Pointer/14-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
int N;
cin >> N;

vector<long int> have(N);
for (int i = 0; i < N; i++) {
cin >> have[i];
}
sort(have.begin(), have.end());

int left = 0, right = N - 1;
long int mix = have[left] + have[right];

int pLeft = left, pRight = right;
long int pMix = mix;

while (left < right) {
long int mix = have[left] + have[right];
if (mix == 0) {
cout << have[left] << " " << have[right];
return 0;
}
else if (abs(mix) < abs(pMix)) {
pMix = mix;
pLeft = left;
pRight = right;
}
if (mix > 0) right--;
else left++;
}
cout << have[pLeft] << " " << have[pRight];

return 0;
}

0 comments on commit f001e97

Please sign in to comment.