# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1273413 | nhq0914 | Stove (JOI18_stove) | C++17 | 1 ms | 332 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);
freopen("data.txt", "r", stdin);
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |