結果
問題 |
No.615 集合に分けよう
|
ユーザー |
![]() |
提出日時 | 2022-07-25 07:05:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 495 bytes |
コンパイル時間 | 2,379 ms |
コンパイル使用メモリ | 197,908 KB |
最終ジャッジ日時 | 2025-01-30 13:57:20 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,k; cin>>n>>k; vector<ll> A(n); rep(i,n) cin>>A[i]; sort(ALL(A)); reverse(ALL(A)); vector<ll> B(n-1); rep(i,n-1) B[i]=A[i]-A[i+1]; sort(ALL(B)); reverse(ALL(B)); ll sum=0; rep(i,k-1) sum+=B[i]; cout<<A[0]-A[n-1]-sum<<endl; return 0; }