# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1252699 | VKhang | Stove (JOI18_stove) | C++20 | 15 ms | 1988 KiB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, MOD = 1e9 + 7;
const long long L = 1e18;
#define ll long long
#define fi first
#define se second
#define yes {cout << "YES";return;}
#define no {cout << "NO"; return;}
#define pb push_back
#define MASK(i) (1ll << (i))
#define BIT(i, s) ((1ll << (i)) & (s))
#define all(a) a.begin(), a.end()
int n, k;
int a[N];
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
vector <pair <int, int>> s;
for (int i = 1; i < n; i++){
s.pb({a[i + 1] - a[i] - 1, i});
}
sort(all(s));
int ans = n;
for (int i = 0; i < s.size() && n > k; i++){
ans += s[i].fi;
n--;
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
if (fopen("VKhang.inp","r")){
freopen("VKhang.inp","r",stdin);
freopen("VKhang.out","w",stdout);
}
solve();
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... |