結果
問題 | No.615 集合に分けよう |
ユーザー |
|
提出日時 | 2018-01-17 14:56:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 507 bytes |
コンパイル時間 | 1,968 ms |
コンパイル使用メモリ | 171,272 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 06:40:49 |
合計ジャッジ時間 | 3,392 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
#include<bits/stdc++.h>#define rep(i,a,n) for (int i = a; i < n; i++)#define per(i,n,a) for (int i = n - 1; i >= a; i--)using namespace std;int main() {int n, k;cin >> n >> k;vector<long> a(n);rep(i, 0, n) {cin >> a[i];}sort(a.begin(), a.end());vector<long> sa(n - 1);rep(i, 0, n - 1) {sa[i] = a[i + 1] - a[i];}sort(sa.begin(), sa.end());long ans = 0;rep(i, 0, n - k) {ans += sa[i];}cout << ans << endl;}