이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#define MOD 1000000007ll
#define EPS 1e-9
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pl;
typedef tuple <ll,ll,ll> tl;
ll N, K, T[100005], A;
vector <ll> gaps;
inline void read(ll& v) {
v = 0;
char ch = getchar_unlocked();
while (ch < '0' || ch > '9')
ch = getchar_unlocked();
while (ch >= '0' && ch <= '9') {
v = (v << 3) + (v << 1) + ch - '0';
ch = getchar_unlocked();
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
read(N);
read(K);
K = min(N, K);
for (ll i = 1; i <= N; i++) read(T[i]);
A = T[N] - T[1] + 1;
for (ll i = 2; i <= N; i++) gaps.push_back(T[i] - T[i-1] - 1);
sort(gaps.begin(), gaps.end(), greater<ll>());
for (ll i = 0; i < K-1; i++) A -= gaps[i];
cout << A;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |