結果
| 問題 |
No.615 集合に分けよう
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-26 20:22:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 674 bytes |
| コンパイル時間 | 2,356 ms |
| コンパイル使用メモリ | 203,840 KB |
| 最終ジャッジ日時 | 2025-01-05 06:31:48 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 WA * 6 |
ソースコード
#include <bits/stdc++.h>
long long greedy(int n, int k, const std::vector<long long> &a) {
std::vector<long long> aa = a;
std::sort(aa.begin(), aa.end());
std::vector<long long> xa(n - 1);
for (int i = 0; i + 1 < n; ++i) {
xa[i] = aa[i + 1] - aa[i];
}
std::sort(xa.begin(), xa.end(), std::greater<int>());
long long res = aa.back() - aa.front();
for (int i = 0; i + 1 < k; ++i) {
res -= xa[i];
}
return res;
}
signed main() {
std::ios::sync_with_stdio(false);
int N, K;
std::cin >> N >> K;
std::vector<long long> A(N);
for (int i = 0; i < N; ++i) {
std::cin >> A[i];
}
std::cout << greedy(N, K, A) << std::endl;
return 0;
}