From 77012492e7b593d41d3ca17d0fd196dcb74ad1f4 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 20 Feb 2025 15:07:46 +0900 Subject: [PATCH] =?UTF-8?q?[20250220]=20BOJ=20/=20G2=20/=20=EA=B8=B0?= =?UTF-8?q?=EC=A7=80=EA=B5=AD=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2 \352\270\260\354\247\200\352\265\255.md" | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 "khj20006/202502/20 BOJ G2 \352\270\260\354\247\200\352\265\255.md" diff --git "a/khj20006/202502/20 BOJ G2 \352\270\260\354\247\200\352\265\255.md" "b/khj20006/202502/20 BOJ G2 \352\270\260\354\247\200\352\265\255.md" new file mode 100644 index 00000000..01c8c970 --- /dev/null +++ "b/khj20006/202502/20 BOJ G2 \352\270\260\354\247\200\352\265\255.md" @@ -0,0 +1,38 @@ +```cpp + +#include +#include +#include +using namespace std; +using ll = long long; + +int main() +{ + cin.tie(0)->sync_with_stdio(0); + + int N; + ll inf = 1e18; + cin >> N; + vector> A(N); + for (auto &[x, y] : A) cin >> x >> y; + sort(A.begin(), A.end()); + + vector dp(10000, inf); + dp[0] = abs(A[0].second) * 2; + for (int i = 1; i < N; i++) { + int p = i; + ll maxabs = -1; + while (i < N && A[p].first == A[i].first) maxabs = max(maxabs, abs(A[i++].second)); + i--; + for (int j = p - 1; j >= 0; j--) { + maxabs = max(maxabs, abs(A[j+1].second)); + dp[i] = min(dp[i], dp[j] + max(maxabs * 2, A[i].first - A[j + 1].first)); + } + maxabs = max(maxabs, abs(A[0].second)); + dp[i] = min(dp[i], max(maxabs * 2, A[i].first - A[0].first)); + } + cout << dp[N - 1]; + +} + +```