結果
問題 | No.615 集合に分けよう |
ユーザー |
![]() |
提出日時 | 2017-12-15 00:11:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 743 bytes |
コンパイル時間 | 896 ms |
コンパイル使用メモリ | 79,080 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-14 13:45:37 |
合計ジャッジ時間 | 2,151 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(0);int n, k;cin >> n >> k;vector<int64_t> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}sort(a.begin(), a.end());if (k == 1) {cout << a[n - 1] - a[0] << endl;quick_exit(0);}vector<int64_t> b(n - 1);for (int i = 0; i < n - 1; i++) {b[i] = a[i + 1] - a[i];}sort(b.begin(), b.end());int64_t r = 0;for (int i = 0; i < k - 1; i++) {r += b[n - 2 - i];}cout << a[n - 1] - a[0] - r << endl;return 0;}