제출 #1033678

#제출 시각아이디문제언어결과실행 시간메모리
1033678vjudge1Stove (JOI18_stove)C++17
100 / 100
14 ms1260 KiB
#include<bits/stdc++.h> #define endl "\n" using namespace std; void solve() { int n, k; cin >> n >> k; vector<int> a(n), s(n - 1); for (int i = 0; i < n; ++i) cin >> a[i]; long long total_time = a[n - 1] - a[0] + 1; for (int i = 0; i < n - 1; ++i) s[i] = a[i + 1] - a[i] - 1; sort(s.begin(), s.end(), greater<int>()); for (int i = 0; i < k - 1; ++i) total_time -= s[i]; cout << total_time; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...