제출 #1273414

#제출 시각아이디문제언어결과실행 시간메모리
1273414nhq0914Stove (JOI18_stove)C++17
100 / 100
14 ms1668 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; int n, k; int ans; int t[maxn]; int gap[maxn], cnt; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for(int i = 0; i < n; ++i){ cin >> t[i]; if(i == 0 || t[i - 1] + 1 == t[i]) continue; gap[cnt++] = t[i] - t[i - 1] - 1; } ans = t[n - 1] - t[0] + 1; sort(gap, gap + cnt, greater <int> ()); cnt = min(cnt, k - 1); for(int i = 0; i < cnt; ++i) ans -= gap[i]; cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...