Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dohyeondol1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
| 5μ°¨μ‹œ | 2025.04.02 | DFS & BFS | [DFS와 BFS](https://www.acmicpc.net/problem/1260)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/18|
| 6μ°¨μ‹œ | 2025.04.05 | DP | [ν‰λ²”ν•œ λ°°λ‚­](https://www.acmicpc.net/problem/12865)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/22|
| 7μ°¨μ‹œ | 2025.04.08 | 트리 | [트리 순회](https://www.acmicpc.net/problem/1991)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/26|
---
<<<<<<< Updated upstream
---
=======
| 8μ°¨μ‹œ | 2025.04.11 | 덱 | [νšŒμ „ν•˜λŠ” 큐](https://www.acmicpc.net/problem/1021)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/32|
| 9μ°¨μ‹œ | 2025.04.30 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [체윑볡](https://school.programmers.co.kr/learn/courses/30/lessons/42862)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/33|
>>>>>>> Stashed changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int solution(int n, vector<int> lost, vector<int> reserve) {
int answer = 0;

answer += n - lost.size();
sort(lost.begin(), lost.end());
sort(reserve.begin(), reserve.end());

for (int i = 0; i < lost.size(); ) {
bool found = false;
for (int j = 0; j < reserve.size(); j++) {
if (lost[i] == reserve[j]) {
lost.erase(lost.begin() + i);
reserve.erase(reserve.begin() + j);
found = true;
answer++;
break;
}
}
if (!found) i++;
}

for(int i = 0; i < lost.size(); i++) {
for(int j = 0; j < reserve.size(); j++) {
if((lost[i]-1) == reserve[j]) {
reserve.erase(reserve.begin());
answer++;
break;
}
else if(lost[i]+1 == reserve[j]) {
reserve.erase(reserve.begin());
answer++;
break;
}
}
}

return answer;
}