結果
問題 | No.615 集合に分けよう |
ユーザー |
|
提出日時 | 2020-07-28 02:52:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 740 bytes |
コンパイル時間 | 2,358 ms |
コンパイル使用メモリ | 195,184 KB |
最終ジャッジ日時 | 2025-01-12 07:03:57 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 TLE * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,n) for(int i=0; i<(int)(n); i++)const long long INF = 1LL<<60;int n, k;long long a[55555];long long dp[2][55555];int main() {ios_base::sync_with_stdio(0);cin.tie(0);cin >> n >> k;REP (i, n) cin >> a[i];sort(a, a + n);REP (i, 2) REP (j, 55555) dp[i][j] = INF;dp[0][0] = 0;REP (i, n) {int cur = i & 1;int nxt = (i + 1) & 1;fill(dp[nxt], dp[nxt]+k+1, INF);REP (j, k+1) {if (dp[cur][j] == INF) continue;if (i >= 1)dp[nxt][j] = min(dp[nxt][j], dp[cur][j] - a[i-1] + a[i]);if (j + 1 <= k)dp[nxt][j+1] = min(dp[nxt][j+1] , dp[cur][j]);}}cout << dp[n&1][k] << endl;return 0;}