# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335880 | Killer2501 | Stove (JOI18_stove) | C++14 | 33 ms | 7916 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>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pb push_back
#define pii pair<ll ,pll>
#define task "C"
using namespace std;
const int N = 2e5+5;
const int M = 4e6+5;
const int mod = 1e9+7;
ll n, t, m, k, a[N], ans, tong, h[N], u, v;
string s;
bool ok;
vector<ll> adj[N], kq;
vector<pll> res;
struct dang
{
ll x, y, h;
}e[N], f[N];
bool cmp(const dang& u, const dang& v)
{
return u.h < v.h;
}
void sol()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++)cin >> a[i];
sort(a+1, a+1+n);
priority_queue<ll> pq;
for(int i = 2; i <= n; i ++)pq.push(a[i]-a[i-1]-1);
ans = a[n] - a[1] + 1;
while(m > 1)
{
ans -= pq.top();
pq.pop();
--m;
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
sol();
}
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... |