結果
問題 | No.615 集合に分けよう |
ユーザー |
|
提出日時 | 2020-07-28 03:13:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 544 bytes |
コンパイル時間 | 2,149 ms |
コンパイル使用メモリ | 197,672 KB |
最終ジャッジ日時 | 2025-01-12 07:04:11 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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++)int main() {ios_base::sync_with_stdio(0);cin.tie(0);int n, k;cin >> n >> k;vector<long long> a(n);REP (i, n) cin >> a[i];sort(a.begin(), a.end());long long sum = a.back() - a.front();if (n > 1) {vector<long long> diff(n-1);for (int i = 1; i < n; i++)diff[i-1] = a[i] - a[i-1];sort(diff.begin(), diff.end());REP (i, k-1)sum -= diff[n-2-i];}cout << sum << endl;return 0;}