#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define ll int
#define all(x) (x).begin(),(x).end()
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
ll a[N],n,k;
vector<ll>v;
void solve()
{
cin >> n >> k;
for(int i = 1; i <= n ; i++) cin >> a[i];
ll ans = a[n] + 1 - a[1];
for(int i = 2; i <= n ; i++) v.pb(a[i] - a[i-1] - 1);
sort(v.begin(),v.end());
int cnt = 0;
for(int i = v.size() - 1 ; i >= 0 ; i--){
if(cnt == k - 1) break;
cnt++;
ans -= v[i];
}
cout << ans << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
stove.cpp:6: warning: "ll" redefined
6 | #define ll int
|
stove.cpp:2: note: this is the location of the previous definition
2 | #define ll long long
|| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |