結果
| 問題 |
No.838 Noelちゃんと星々3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-06-15 17:59:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,118 bytes |
| コンパイル時間 | 1,745 ms |
| コンパイル使用メモリ | 168,948 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-19 05:40:22 |
| 合計ジャッジ時間 | 2,405 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include "bits/stdc++.h"
// Custom Header <<<
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n) for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
// >>>
struct FastIO {
FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;
signed main()
{
int N;
int a[100010];
cin >> N;
rep(i, 0, N) cin >> a[i];
sort(a, a+N);
i64 dp[100010];
dp[0] = LINF;
dp[1] = a[1] - a[0];
if (2 < N) dp[2] = a[2] - a[0];
for (int i = 3; i < N; ++i) {
dp[i] = min(
dp[i-2] + (a[i] - a[i-1]),
dp[i-3] + (a[i] - a[i-2]));
}
cout << (dp[N-1]) << endl;
return 0;
}
/* vim:set foldmethod=marker foldmarker=<<<,>>> : */