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>
using namespace std;
#define ll long long
const ll N = 1e5 + 5 ;
const ll INF = 0x3f3f3f3f3f3f3f3f ;
const ll MOD = 1e9 + 7 ;
ll n , k , a[N] , res = 0 ,ans = 0 ;
vector< ll > v ;
int main()
{
cin >> n >> k ;
for( int i = 1 ; i <= n ; i++) cin >> a[i] ;
for( int i = 2 ; i <= n ; i++)
{
v.push_back(a[i] - a[i-1] - 1 ) ;
}
sort( v.begin() , v.end() ) ;
reverse(v.begin() , v.end() ) ;
for( int i = 0 ; i < k -1 ; i++) res += v[i] ;
cout << a[n] - a[1] + 1 - res << '\n' ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |