Skip to content

Commit

Permalink
2024-04-02 두 용액
Browse files Browse the repository at this point in the history
  • Loading branch information
rivkms committed Apr 2, 2024
1 parent 76a188d commit 82459ab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rivkms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
| 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) |
40 changes: 40 additions & 0 deletions rivkms/Two_pointer/2470.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
int n;
cin >> n;
vector<int> vec(n,0);
for(int i = 0; i<n; i++){
cin >> vec[i];
}
sort(vec.begin(), vec.end());
vector<int> 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;
}

0 comments on commit 82459ab

Please sign in to comment.