結果
| 問題 |
No.615 集合に分けよう
|
| コンテスト | |
| ユーザー |
mencotton
|
| 提出日時 | 2020-11-02 22:41:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 497 bytes |
| コンパイル時間 | 657 ms |
| コンパイル使用メモリ | 77,404 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 08:13:15 |
| 合計ジャッジ時間 | 2,359 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)cin >> a[i];
sort(a.begin(), a.end());
vector<ll> b(n - 1);
for (int i = 0; i < n - 1; i++)b[i] = a[i + 1] - a[i];
sort(b.begin(), b.end(), greater<>());
ll ret = a.back() - a.front();
for (int i = 0; i < k - 1; i++)ret -= b[i];
cout << ret << endl;
return 0;
}
mencotton