結果
| 問題 | No.838 Noelちゃんと星々3 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-04 02:59:04 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 661 bytes |
| 記録 | |
| コンパイル時間 | 1,196 ms |
| コンパイル使用メモリ | 78,872 KB |
| 最終ジャッジ日時 | 2025-01-12 14:10:48 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 17 |
ソースコード
#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 = 2; i < n; ++i) {
for (int k = 1; k <= 2; ++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;
}