제출 #656999

#제출 시각아이디문제언어결과실행 시간메모리
656999mdubStove (JOI18_stove)C++14
100 / 100
58 ms2036 KiB
#include <bits/stdc++.h> using namespace std; int main () { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); vector<int> espaces(n- 1); for (int i = 1; i < n; i++) { espaces[i-1] = a[i]-a[i- 1] - 1; } sort(espaces.begin(), espaces.end()); int ans= a[n - 1]+1-a[0]; for (int i = n - 2; i > n - 2 - (k -1); i--) { ans -= espaces[i]; } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...