# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1241910 | long123 | Stove (JOI18_stove) | C++20 | 14 ms | 2376 KiB |
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
if(fopen(".inp", "r"))
{
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
int n, k;
cin >> n >> k;
vector<int> t(n);
for ( int i = 0; i < n; i++ )
{
cin >> t[i];
}
vector<int> gaps;
sort(t.begin(), t.end());
for ( int i = 1; i < n; i++ )
{
int gap = t[i] - (t[i - 1] + 1);
if(gap > 0)
{
gaps.push_back(gap);
}
}
sort(gaps.rbegin(), gaps.rend());
int tong = t.back() + 1 - t[0];
int luu = 0;
for ( int i = 0; i < min(k - 1, (int)gaps.size()); i++ )
{
luu += gaps[i];
}
cout << tong - luu << "\n";
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... |