diff --git a/rivkms/README.md b/rivkms/README.md index 1b0ecbc..24b6cef 100644 --- a/rivkms/README.md +++ b/rivkms/README.md @@ -9,4 +9,5 @@ | 5차시 | 2024.02.24 | Backtracking | [입대](https://www.acmicpc.net/problem/31413) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/18) | | 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) | \ No newline at end of file +| 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 diff --git a/rivkms/Two_pointer/3273.cpp b/rivkms/Two_pointer/3273.cpp new file mode 100644 index 0000000..415f456 --- /dev/null +++ b/rivkms/Two_pointer/3273.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +using namespace std; +int main(){ + int n, goal; + int a, b, cnt = 0;; + cin >> n; + a = 0; + b = n-1; + vector vec(n,0); + for(int i = 0; i> vec[i]; + } + sort(vec.begin(), vec.end()); + cin >> goal; + while(true){ + if(b<=a){ + cout << cnt; + break; + } + if(vec[a]+vec[b] == goal){ + cnt++; + a+=1; + b-=1; + } + else if(vec[a]+vec[b] > goal){ + b-=1; + } + else{ + a+=1; + } + } + return 0; +} \ No newline at end of file