結果
問題 | No.615 集合に分けよう |
ユーザー |
![]() |
提出日時 | 2018-04-03 16:41:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 616 bytes |
コンパイル時間 | 1,625 ms |
コンパイル使用メモリ | 168,964 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 08:29:45 |
合計ジャッジ時間 | 3,557 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int K; cin >> K; long long int a[50004]; for (int i = 0; i < N; i++) { cin >> a[i]; } long long ans = 0; sort(a, a + N); ans = a[N - 1] - a[0]; long long int b[50004]; for (int i = 0; i < N - 1; i++) { b[i] = a[i + 1] - a[i]; } sort(b, b + N - 1); /*for (int i = 0; i < N - 1; i++) { cout << b[i] << " "; }cout << endl;*/ long long sum = 0; for (int k = 0; k < K - 1; k++) { sum += b[N - 2 - k]; } //cout << "ans :" << ans << endl; //cout << "sum :" << sum << endl; cout << ans - sum << endl; return 0; }