# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102464 | sktodow | Stove (JOI18_stove) | C++17 | 18 ms | 3164 KiB |
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>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pb push_back
#define mid a+(b-a)/2
const int N=5e5+5;
const int MOD=1e9+7;
const int inf=2e18+5;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
void io(string name = ""){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n,k; cin>>n>>k;
vector<int>arr(n);
for(auto &a:arr){cin>>a;}
sort(arr.begin(),arr.end());
vector<int>dis;
for(int i=1;i<n;i++){
dis.pb(arr[i]-arr[i-1]-1);
}
sort(dis.rbegin(),dis.rend());
int ans=0;
for(int i=0;i<min(k-1,(int)dis.size());i++){
ans+=dis[i];
}
cout<<arr[n-1]-arr[0]+1-ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |