Skip to content

Commit

Permalink
Merge pull request #38 from AlgoLeadMe/9-rivkms
Browse files Browse the repository at this point in the history
9-rivkms
  • Loading branch information
rivkms authored Apr 2, 2024
2 parents 8170841 + 6a0b253 commit 76a188d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rivkms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
| 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) |
36 changes: 36 additions & 0 deletions rivkms/Two_pointer/3273.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
int n, goal;
int a, b, cnt = 0;;
cin >> n;
a = 0;
b = n-1;
vector<int> vec(n,0);
for(int i = 0; i<n; i++){
cin >> 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;
}

0 comments on commit 76a188d

Please sign in to comment.