제출 #330113

#제출 시각아이디문제언어결과실행 시간메모리
330113casperwangStove (JOI18_stove)C++14
100 / 100
24 ms2416 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; const int MAXN = 100000; int n, k; int a[MAXN+1]; vector <int> d; int ans; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a+n); for (int i = 1; i < n; i++) d.pb(a[i] - a[i-1] - 1); sort(d.begin(), d.end(), greater<int>()); ans = a[n-1] - a[0] + 1; for (int i = 0; i < k-1; i++) { ans -= d[i]; } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...