이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define int long long
#define str string
#define fastio ios::sync_with_stdio(0), cin.tie(0);
#define fs first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define len(x) x.size()
#define print(a) \
for (auto &x : a) \
cout << x << " "; \
cout << endl;
#define printmp(a) \
for (auto &x : a) \
cout << x.fs << " " << x.ss << endl;
const int mod = 1e9 + 7;
const long long INF = LLONG_MAX;
const long long NEG_INF = LLONG_MIN;
void solve()
{
int n, k;
cin>>n>>k;
vector<int> a(n);
for(int i = 0; i < n; i ++)cin>>a[i];
vector<int> diff(n - 1);
for(int i = 0; i < n - 1; i ++)diff[i] = a[i + 1] - a[i] + 1;
int ans = n;
sort(all(diff));
for(int i = 0; i < n - k; i ++)ans += diff[i], ans -= 2;
cout<<ans;
}
signed main()
{
fastio int t = 1;
// cin >> t;
while (t--)
{
solve();
cout << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |