이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//abeke
typedef long long ll;
typedef unsigned long long ull;
#define all(x) x.begin(), x.end()
//#define sz(x) (int)x.size()
#define pb push_back
#define speed ios::sync_with_stdio( false); cin.tie(nullptr); cout.tie(0);
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define eb emplace_back
#define nl '\n'
#define f first
#define s second
#define gcd __gcd
#define ins insert
const int inf = INT_MAX;
const int mod = 1e9+7;
const int N = 2e5+5;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
forn (i, n) cin >> a[i];
vector<int> v;
int ans = a[n-1]-a[0]+1;
for (int i = 1; i < n; i++) {
v.pb(a[i]-a[i-1]-1);
}
sort(all(v));
k--;
for (int i = v.size()-1; i >= 0 && k > 0; i--) {
ans -= v[i];
k--;
} cout << ans;
}
int main()
{
speed;
solve();
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... |