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>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<bool> vb;
ll mod = 1e9 + 7;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(ll i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
using namespace std;
//ll ans;
/*void bfs(vvp64 adj, ll source, ll n, ll choice, vb used, v64 val)
{
queue<p64>q;
// v64 d(n, LLONG_MAX);
q.push(mp(source, LLONG_MAX));
//vb used(n, false);
//d[source] = 0;
used[source] = true;
while(!q.empty())
{
p64 v = q.front();
q.pop();
for(p64 u : adj[v.fi])
{
if(!used[u.fi]){
if(u.se >= choice){
used[u.fi] = true;
//u.se = min(u.se, v.se);
//val[u.fi] = u.se;
q.push(u);
ans++;
}
}
}
}
//ofstream fout("mootube.out");
//fout << ans << '\n';
//return ans;
}*/
void solve(ll it)
{
ll n, k;
cin >> n >> k;
v64 A(n);
for(ll &x : A) cin >> x;
v64 B;
if(n == 1){
cout << 1;
return;
}
if(k >= n){
cout << n;
return;
}
FOR(1, n - 1, i)
{
B.pb(A[i] - A[i - 1] - 1);
}
sort(rall(B));
ll j = min((ll)B.size(), k - 1), ans = 0;
for(int i = 0; i < B.size(); i++)
{
if(k == 1) break;
ans += B[i];
k--;
}
cout << A[n - 1] - A[0] - ans + 1;
}
int main()
{
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
fast_cin();
ll t = 1;
//cin >> t;
for(int it=1; it<=t; it++)
{
// cout << "Case #" << it+1 << ": ";
solve(it);
}
return 0;
}
Compilation message (stderr)
stove.cpp: In function 'void solve(ll)':
stove.cpp:96:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int i = 0; i < B.size(); i++)
| ~~^~~~~~~~~~
stove.cpp:94:9: warning: unused variable 'j' [-Wunused-variable]
94 | ll j = min((ll)B.size(), k - 1), ans = 0;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |