/***********************************************************
When you are inspired by passion
and you want to live for the current moment
When your every thought and action
has the power to become the story of your future
When difficulties stand to demolish your Glory
Just remember that Life is a 'Golden adverse Story'
Withstand it to acheive your passion and dreams
more amazingly more easily.
Why then? When writing the story of your Life
You want to Let someone else hold your pen
huzaifa242©
***********************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int int32_t
#define MAX 100005
#define x first
#define y second
int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX)
{return uniform_int_distribution<int>(l,r)(rng);}
template <typename T,typename G>
ostream& operator << (ostream& out, const pair<T,G> &a)
{return out<<"( "<<a.x<<", "<<a.y<<")";}
template <typename T>
ostream& operator << (ostream& out, const vector<T> &a)
{out<<"[ ";for(const auto &i:a)out<<i<<", ";return out<<"]"<<endl;}
template <typename T>
ostream& operator << (ostream& out, const set<T> &a)
{out<<"{ ";for(const auto &i:a)out<<i<<", ";return out<<"}"<<endl;}
template <typename T,typename G>
ostream& operator << (ostream& out, const map<T,G> &a)
{out<<"< ";for(const auto &i:a)out<<i<<", ";return out<<">"<<endl;}
template<typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
ostream&>::type operator<<(ostream& out, T(&a)[N])
{out<<"[ ";for(size_t i=0;i<N;++i)out<<a[i]<<", ";out <<"]"<<endl;return out;}
void debug_out(){cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr<<(H)<<" ";debug_out(T...);}
#ifdef LOCAL
#define debug(...) cerr<<"#"<<#__VA_ARGS__<<":\n",debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,k,i;
cin>>n>>k;
vector<int> a(n),d;
for(i=0;i<n;i++)
cin>>a[i];
for(i=1;i<n;i++){
d.push_back(a[i]-a[i-1]-1);
}
sort(d.rbegin(),d.rend());
int ans=a[n-1]-a[0]+1;
for(i=1;i<k;i++)
ans-=d[i-1];
cout<<ans<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
29 ms |
2432 KB |
Output is correct |
17 |
Correct |
28 ms |
2432 KB |
Output is correct |
18 |
Correct |
28 ms |
2432 KB |
Output is correct |
19 |
Correct |
28 ms |
2432 KB |
Output is correct |
20 |
Correct |
29 ms |
2432 KB |
Output is correct |
21 |
Correct |
28 ms |
2304 KB |
Output is correct |
22 |
Correct |
29 ms |
2300 KB |
Output is correct |
23 |
Correct |
29 ms |
2432 KB |
Output is correct |
24 |
Correct |
30 ms |
2288 KB |
Output is correct |