結果
| 問題 |
No.838 Noelちゃんと星々3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-04 03:03:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 675 bytes |
| コンパイル時間 | 881 ms |
| コンパイル使用メモリ | 78,868 KB |
| 最終ジャッジ日時 | 2025-01-12 14:10:54 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using lint = long long;
constexpr lint INF = 1LL << 60;
void solve() {
int n;
std::cin >> n;
std::vector<lint> xs(n);
for (auto& x : xs) std::cin >> x;
std::sort(xs.begin(), xs.end());
std::vector<lint> dp(n + 1, INF);
dp[0] = 0;
for (int i = 1; i < n; ++i) {
for (int k = 1; k <= 2 && i - k >= 0; ++k) {
lint cost = xs[i] - xs[i - k];
dp[i + 1] = std::min(dp[i + 1], dp[i - k] + cost);
}
}
std::cout << dp[n] << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}