| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1287676 | quan606303 | Stove (JOI18_stove) | C++20 | 21 ms | 2408 KiB |
/*
* @Author: RMQuan
* @Date: 2025-11-05 09:33:52
* @Last Modified by: RMQuan
* @Last Modified time: 2025-11-05 09:39:06
*/
/*idea :
*/
#include <bits/stdc++.h>
bool M1;
#define int long long
#define ll long long
#define INTMAX INT_MAX
#define INTMIN INT_MIN
#define LONGMAX LLONG_MAX
#define LONGMIN LLONG_MIN
#define fi first
#define se second
#define memfull(a,b) memset(a,b,sizeof(a));
#define endl '\n'
#define TASK "TEST"
#define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
using namespace std;
const int MOD=1e9+7;
const int maxn=1e5+7;
int n,k,a[maxn];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
file();
cin>>n>>k;
for (int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+1+n);
vector<int> vt;
for (int i=1;i<n;i++)vt.push_back(a[i+1]-a[i]);
sort(vt.begin(),vt.end());
if (n<=k)cout<<n<<endl;
else{
int ans=n;
for (int i=1;i<=n-k;i++)ans+=(vt[i-1]-1);
cout<<ans;
}
bool M2;
cerr<<"-------------------------------------------------"<<endl;
cerr<<"Time : "<<clock()<<" ms"<<endl;
cerr<<"Memory : "<<abs(&M2-&M1)/1024/1024<<" MB"<<endl;
cerr<<"-------------------------------------------------"<<endl;
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... | ||||
