# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
59946 | gusfring | Stove (JOI18_stove) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
int t[MAXN], a[MAXN], N, K;
int main(){
int N, K;
scanf("%d %d", &N, &K);
for(int i=0; i<n; ++i) scanf("%d", &t[i]);
int res = t[n - 1] + 1 - t[0];
for(int i=0; i<n-1; ++i) a[i] = t[i + 1] - t[i] - 1;
std::sort(a, a + n - 1, std::greater<int>());
for(int i=0; i<k-1; ++I) res -= a[i];
printf("%d",res);
}