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 <chrono>
#define unint unsigned int
#define sint signed int
#define shint short int
#define usint unsigned short int
#define lint long int
#define ulint unsigned long int
#define ll long long
#define ull unsigned long long
#define ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf 1e15
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
using namespace std;
using namespace std::chrono;
/*auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
vector<char> abecede = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
cout << "Time taken by function: " << duration.count() << " microseconds" << endl;*/
void solve(){
}
#define maxn 100005
int a[maxn];
bool cmp(pair<int,int> a,pair<int,int> b){
return a.fi-a.sc>b.fi-b.sc;
}
int main(){
int n,k;
cin >> n>>k;
for(int i = 0;i<n;i++) cin >> a[i];
sort(a,a+n,greater<int>());
vector<pair<int,int> > v;
int ans = n;
for(int i = 0;i<n-1;i++){
v.pb({a[i+1]+1,a[i]});
}
sort(v.begin(),v.end(),cmp);
//for(auto &it : v) cout<<it.fi<< " "<<it.sc<<"\n";
for(int i=0;i<n-k;i++){
ans+=v[i].sc-v[i].fi;
}
cout<<ans;
}
Compilation message (stderr)
stove.cpp:11:9: warning: ISO C++11 requires whitespace after the macro name
11 | #define ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(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... |