| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1351258 | nguthianmangcay | Stove (JOI18_stove) | C++20 | 18 ms | 1468 KiB |
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+3;
const long long inf=1e18+3;
#define ll long long
#define fi first
#define se second
#define VOI void
int a[N];
VOI jiangly(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+1+n);
priority_queue<int>q;
for(int i=2;i<=n;i++){
q.push(a[i] - a[i-1]-1);
}
ll ans = a[n] - a[1] + 1;
int cnt = 0;
while(!q.empty() && cnt < k - 1){
cnt++;
ll add = q.top();
q.pop();
ans -= add;
}
cout<<ans;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
if(fopen("QUANSENSEI.inp","r")){
freopen("O(0).inp","r",stdin);
}
// if(fopen("input.txt","r")){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// }
jiangly();
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
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... | ||||
