This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(7)<<(x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define loop(i,a,b) for (int i=a; i<b; ++i)
using ll = long long;
const int mod = 998244353;
typedef pair<int , int> pairs;
typedef complex<ll> G;
const int N = 1e3 + 5;
int power(int a,int b){
if(!b)
return 1;
int c=power(a,b/2);
c=(1LL*c*c)%mod;
if(b%2)
c=(1LL*c*a)%mod;
return c;
}
void done() {
}
/*string solve_palindrome(const string& s)
{
string a = s;
reverse(a.begin(), a.end());
//a = s + "#" + a;
int c = 0;
for (int i = 1; i < (int)a.size(); i++)
{
while (c != 0 && a[c] != a[i])
c = pref[c - 1];
if (a[c] == a[i])
c++;
pref[i] = c;
}
return s.substr(0, c);
}
*/
/*3
3 7 7 9 11
4 6 6 7*/
void solve()
{
int n, k;
cin >> n >> k;
int a[n];
for(int i = 0;i < n;++i) {
cin >> a[i];
}
for(int i = n - 1;i > 0;--i) {
a[i] -= a[i - 1] + 1;
}
sort(a + 1,a + n);
ll ans = n;
for(int i = 1;i <= n-k;++i) {
ans += a[i];
}
cout << ans << '\n';
}
void another() {
}
void test_case() {
int t;
cin >> t;
while(t--)another();
}
int main() {
ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |