Skip to content

Commit

Permalink
24-09-04 세 용액
Browse files Browse the repository at this point in the history
  • Loading branch information
makehard23 committed Sep 4, 2024
1 parent 6367547 commit 6413079
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
| 23차시 | 2024.08.05 | LCS | [LCS 2](https://www.acmicpc.net/problem/9252) | - |
| 24차시 | 2024.08.14 | 위상정렬 | [줄 세우기](https://www.acmicpc.net/problem/2252) | - |
| 25차시 | 2024.08.17 | 수학 | [신기한 소수](https://www.acmicpc.net/problem/2023) | - |
| 27차시 | 2024.09.04 | 이분탐색 | [세 용액](https://www.acmicpc.net/problem/2473) | - |
---
42 changes: 42 additions & 0 deletions yuyu0830/탐색/2473.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int n;
ll arr[5001] = {0, };
ll minValue = 999999999999;
ll ans[3] = {0, };

int main() {
cin >> n;

for (int i = 1; i <= n; i++)
cin >> arr[i];

sort(arr + 1, arr + n + 1);

for (int i = 1; i <= n; i++) {
ll start = i + 1;
ll end = n;

while (start < end) {
ll cur = arr[i] + arr[start] + arr[end];

if (abs(cur) < minValue) {
minValue = abs(cur);

ans[0] = arr[i];
ans[1] = arr[start];
ans[2] = arr[end];
}

if (cur < 0) start++;
else end--;
}
}

printf("%d %d %d\n", ans[0], ans[1], ans[2]);
}

0 comments on commit 6413079

Please sign in to comment.