diff --git a/dohyeondol1/README.md b/dohyeondol1/README.md index ecae6d3..d2234fe 100644 --- a/dohyeondol1/README.md +++ b/dohyeondol1/README.md @@ -10,3 +10,4 @@ | 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| | 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| \ No newline at end of file diff --git "a/dohyeondol1/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/9-dohyeondol1.cpp" "b/dohyeondol1/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/9-dohyeondol1.cpp" new file mode 100644 index 0000000..8b93b6c --- /dev/null +++ "b/dohyeondol1/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/9-dohyeondol1.cpp" @@ -0,0 +1,43 @@ +#include +#include +#include +using namespace std; + +int solution(int n, vector lost, vector 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; +} \ No newline at end of file