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>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
using namespace std; //using namespace __gnu_pbds; using namespace chrono;
#define ff first
#define ss second
#define pb push_back
#define gan(x) x.begin(),x.end()
#define rgan(x) x.rbegin(),x.rend()
#define ins insert
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update
typedef long long ll;typedef vector<ll> vecs;typedef vector<vector<ll>> matrix;
const int mod = 1e9+7; const char nl = '\n';
const ll N = 1e5+5;
const ll inf = 1e18;
void ShikiMoril() {
ll n; cin >> n; ll s; cin >> s ; s-- ;
vecs vec ( n ), v1;
forn ( i , n ) cin >> vec [ i ];
for ( ll i = 0 ; i + 1 < n ; i ++ ) v1 . pb ( vec [ i + 1 ] - vec [ i ] - 1) ;
sort ( rgan ( v1) ) ;
ll ans = vec [ n - 1 ] + 1 - vec [ 0 ] ;
forn ( i ,s ) ans -= v1 [ i ] ;
cout << ans ;
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
ll t = 1; //cin >> t;
while (t--) {
ShikiMoril();
}
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... |