結果
| 問題 |
No.615 集合に分けよう
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-05 04:03:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 383 bytes |
| コンパイル時間 | 2,808 ms |
| コンパイル使用メモリ | 196,716 KB |
| 最終ジャッジ日時 | 2025-01-10 06:37:55 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | int n,k; scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | rep(i,n) scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
int n,k; scanf("%d%d",&n,&k);
vector<lint> a(n);
rep(i,n) scanf("%lld",&a[i]);
sort(a.begin(),a.end());
vector<lint> d(n-1);
rep(i,n-1) d[i]=a[i+1]-a[i];
sort(d.begin(),d.end());
printf("%lld\n",accumulate(d.begin(),d.end()-k+1,0LL));
return 0;
}