結果
問題 | No.615 集合に分けよう |
ユーザー |
|
提出日時 | 2020-05-03 17:29:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 606 bytes |
コンパイル時間 | 1,677 ms |
コンパイル使用メモリ | 175,772 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-13 00:38:07 |
合計ジャッジ時間 | 2,943 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define llong long longint main() {int n, k;cin >> n >> k;vector<llong> a(n);rep(i, n) cin >> a[i];sort(a.begin(), a.end());if(k == 1) {cout << a[n-1] - a[0] << "\n";} else {priority_queue<llong> borders;rep(i, n-1) {borders.push(a[i+1] - a[i]);}llong result = a[n-1] - a[0];rep(i, k-1) {result -= borders.top();borders.pop();}cout << result << "\n";}}