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 <iomanip>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define for_t ll T;cin>>T;while(T--)
#define endl "\n"
#define F(a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define pb push_back
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,std::less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
*/
void sol()
{
ll n,k;
cin >> n >> k;
ll a[n];
for(int i = 0;i < n;i++)
{
cin >> a[i];
}
sort(a,a + n);
vector<ll> gaps;
for(int i = 1;i < n;i++)
{
gaps.pb(a[i] - a[i - 1] - 1);
}
sort(all(gaps));
ll time = n;
for(int i = 0;i < n - k;i++)
{
time += gaps[i];
}
cout << time << endl;
}
int main()
{
//freopen("milkvisits.in", "r", stdin);
//freopen("milkvisits.out", "w", stdout);
//iota(all(link),0);
FIO
sol();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |