/*
.:-=++***#***+=:.
.:-==+**##**%########***#####*=:.
.-+#%%#*****############**#******#####+=:
.-*%#####********###########*********#######*+-:
:+#######**********########*****+********##########+-.
:+##########**###******##********************###########+:
:+##########*****#*******###**********************###***####*:
.=###########***###*******#***************************#****#####*:
:*#################******************************************######=
-###################***************+****************************#####*:
.=###################******************************************#****#####+.
:*###################*******************************+************#*****#####:
=#############**######*****#*******************++***++++++***************#####=
.*###########******####*****#************+++*+**+++***++++++++***#**********#####+
-############********###*****%*+****+++++++++++++++++***++++++++***#*****#****#####*
=############********###+++++##++++++++++++++++*++++++****++++******##*+++*#****#####*.
.+#*##########*********###+++++%*++==++++++++++++*+++++*#************#*##*+++##****#####*.
.*#=-##########********###*++++*%*+++++++++++++*****+******#***********#*##*+++####*######*.
.:-: .*#: *#########*********###+++++##****++*******************#*#**********##*#*****####*#%###%*.
.--:++=+. .**. ##########********##*#++***%#****+*************=#*****#*#**********##*##*##*####**#%###%*:
:++===== .**. -###########******##*##+****%#*****#************-********#**********#***%####*###***#%######=:
.-=++= =*. +############****###*##*****%#*****%####*####**#:=#***#**#**********#=##*###**####***#%########+:
. .#. .####################*##*****%#####*%#****##****#.:#***#*#**********#%:##*+##***%###***############+:
-- -###################**#*****####****##****##*****..#*****#**********#*.*#+ +##**#####***##############+-.
-=+++-. = +###################**#*****###**********#*#***#: .***#*#***********#:.*#- :**#*######***#######%%%####%%#=:
.++====++ = ####################**##*****###***#+****#=#**** .+*###************+ ## +***######****##########+--+#%%%%+:
.---:=+======+: +. ##################%#***#*****####****#**#+-####. .+###***##*******# .#: :***########***##%%%####%#=. .:=*%%
---==++=======+= -= .%#################%****#*****######-#*##*.=%#*. +=---:::.......: =: =**#########***#%%%%%%%%%%%=. .-
:-:===========+= .#. :%################%%****#*****#####= :-+***#*=. .*#########%%#**#*=%%%%%%%%%%=.
.---=========+= :*. -#################%%****#*****%#+-.-*#%%%@###*= +##########%%%***:+-#%%%#####*:
.:=++++====+- =*.=###%############%@%****#*****#. =###%%%@@@+ ###########%%%%#*#: -*########=
..:::::-. +*+###%####%######%%+******#****#=##= -@@@@@@@+ =*###########%%%%##+ :*#######+
=%##+%####%######%+.******#*****%%#-:+@@@@%-=* +..###########%##%%%*. -#######
%##=#####%###%%#%:=******#*****%*.**##*+=: . -+**####*=: - .=###############%%*: .+#####
.%###%########%%%%:.#*****##*****= .+: . :-::.:--=++- : .-*##################+: :####
:##.*###########%@# #************+ .:.-==-- . +**###+*##############*: .*##
-%- ############%@@-#*###*#=##***#. :. =*++*#**++*##############*- .##
=# ############@@@######*#:###*##= :..+*++++***+++++*##############=.+#
+: ###########%@%%%%######.=###### .=+#+++++++***+++++****##############
.+ *##########%%%%%%######::######= =+++#*+++++++*#+++++******###########
+: =%#%######%%%##%@######:-+######. .:------== :*++++**+++++++*#*+++++********#######
-* :%%%%#####%%%##%%%#####***######* -=--------=: -*+++++++*++++++++*#**+++*=:=******+==*
.*+ +%%%%###%%####%%%#####**+#######= -........:=: -++++++++++*#**##***+******++- .-******=.
-*= *%%%%##%%%%%%%#%#####**++#######. :.........- .=#%%%######%##########%#+*******. .-++++*+
-*+ .*%%%%#%%#######%#####*++++######*: ......... :=#%@@%%%%%%#################*++*****=. .-++++
:**. :###%%%#%%########%####*++++*#######=-:.. -+#%%%###########################++++****#=. .-++
-*+ .######%%%%#########%###@@@%%%%######+...:----:. :*%################################%*+++++*+###- .+
:*+.=########%%%%###########%%%%%%%%######-........:------::.+%%%%%###############%#############%*+++++*.:*##+. .
-+####****##%%%%%%%%###%########%%@%#####:.......:::::::...=@@%%%@###############%############%*+++++*. =##+
+#*##*****####%%%%##%%%%#########%@%#####:.....-:....:..::=*=++++############################%#*+++++ -##.
=%**********#######%%###############%*#####=...=. . :-=-: .###############%#******####%#####+= +*
*#************#############%%#######**+*%####-.- .-:=##############%*********##%#######=: .+.
*#****************##**######%%%###*: ::*#####: -:: .-+####%%%####%*********#%##########*-:
=#***********************######%*- .--:=:. =. :--: .-=*###%###*********#######*#######+-
.#**************************###= .:. ::... .=. +***#%##*******#########***#######+:
=##**************************: :-:--. .. .+..... + =******#%#####%##########***#####**#
####**********************+. . :#########+-=:.... -: +***********##%%#***######****##****
.#%####******************- *##########*:....... ...:. #**************##*********###*##****
:#%@%%%###************* =#*******####+....... :-. *#***************%************#%#****
.#**###%%%%%######****#. =#***********#=....:-. :*#****************##*************####*
*#**#****#####%%%%##### =#*************+=: .=-::..:-*#*****************##*****************##
-#***#*******######%%%%= :=*#**********: ... ##*##%##*******************#********************
.%*****#*********######%. ....:-=*- :++: =#****##%####*************###********************
:. +#*****#**********####%+ ..-*#***#+=##*******##%%###********####*********************
.:-:. .%#*****#**********#%%%* :=+**##########******###********#%%%%%%##****###***********************
-- =%#******#*********@#%%-. :#%%%%%%%%%%%%%%###*****###*****#%%##%%%#%@#####*************************
=-. .=. ##*******#********#%#**###*+=-:.: -######%##%###%####%%%%%##########%####%%%%##%*************####************
==== .= :%#*******#********%%***************++#%%#%#######%###%#######%%%%%%%########%%%%####%#************####***********
==== -: *%#*******#********@#********************#%#######%###%###########%%%%%#####%%%#######%%#**********#####**********
:+=+. = .%###*******#******#%#*******************#%#############%##############%%%##%######***####%%#*******######*********
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n,k,a;
cin >> n >> k;
vector<int> inputarr;
vector<int> arr;
for(int i=0; i<n; i++)
{
cin >> a;
inputarr.push_back(a);
}
sort(inputarr.begin(),inputarr.end());
long long ans = (inputarr[n-1]-inputarr[0])+1;
for(int i=1; i<n; i++)
{
arr.push_back((inputarr[i]-inputarr[i-1])-1);
}
arr.push_back(0);
arr.push_back(0);
sort(arr.begin(),arr.end(),greater<int>());
for(int i=0; i<(k-1); i++)
{
ans-=arr[i];
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
480 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
480 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
33 ms |
2308 KB |
Output is correct |
17 |
Correct |
32 ms |
2516 KB |
Output is correct |
18 |
Correct |
31 ms |
2504 KB |
Output is correct |
19 |
Correct |
32 ms |
2440 KB |
Output is correct |
20 |
Correct |
31 ms |
2484 KB |
Output is correct |
21 |
Correct |
31 ms |
2504 KB |
Output is correct |
22 |
Correct |
31 ms |
2504 KB |
Output is correct |
23 |
Correct |
31 ms |
2436 KB |
Output is correct |
24 |
Correct |
32 ms |
2508 KB |
Output is correct |