# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1273412 | nhq0914 | Stove (JOI18_stove) | C++17 | 259 ms | 327680 KiB |
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vi vector <int>
#define pb push_back
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using pq_min = priority_queue <T, vector <T>, greater <T>>;
const int maxn = 1e5 + 1;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
freopen("data.txt", "r", stdin);
int n, k;
cin >> n >> k;
int t[n];
vector <int> gap;
for(int i = 0; i < n; ++i){
cin >> t[i];
if(i == 0) continue;
if(t[i - 1] + 1 == t[i]) continue;
gap.push_back(t[i] - t[i - 1] - 1);
}
sort(rall(gap));
int ans = t[n - 1] + 1 - t[0];
for(int i = 0; i < n - k; ++i){
if(i == (int) gap.size()) break;
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... |