이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("O3,unroll-loops,inline,no-stack-protector")
// #pragma GCC target("avx,avx2,sse3,ssse3,sse4.1,sse4.2,fma,bmi2,abm,popcnt,mmx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define trace(x) cerr << #x << ": " << (x) << endl;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
#define int ll
constexpr int INF = numeric_limits<int>::max() / 2;
void solve() {
int n, k;
cin >> n >> k;
vector<int> t(n);
for (int& i : t)
cin >> i;
vector<int> diff(n - 1);
for (int i = 1; i < n; ++i)
diff[i - 1] = t[i] - t[i - 1];
sort(all(diff));
int ans = 0;
for (int i = 0; i <= n - 1 - k; ++i)
ans += diff[i];
cout << ans + k;
}
signed main() {
#ifdef LOCAL
freopen("input.in", "r", stdin);
#else
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
#ifdef LOCAL
cerr << '\n' << "time = " << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
#endif
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... |