제출 #1129258

#제출 시각아이디문제언어결과실행 시간메모리
1129258ziewaczStove (JOI18_stove)C++20
100 / 100
16 ms1096 KiB
#include <bits/stdc++.h> #define imie(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n' using namespace std; typedef long long ll; typedef long double ld; const int MOD = 1000000007; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> T(n); for(int i = 0; i < n; i++) { cin >> T[i]; } vector<int> diff(n, 0); for(int i = 1; i < n; i++) { diff[i] = T[i] - T[i - 1] - 1; } sort(diff.rbegin(), diff.rend()); ll ans = T[n - 1] + 1 - T[0]; for(int i = 0; i < k - 1; i++) { ans -= max(0, diff[i]); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...