Submission #1332017

#TimeUsernameProblemLanguageResultExecution timeMemory
1332017nobasistakenStove (JOI18_stove)C++20
100 / 100
13 ms1996 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define endl '\n'
bool testcases=0;
int dx[]={-1,1,-1,1,2,2,-2,-2};
int dy[]={-2,-2,+2,2,-1,1,-1,1};
const int MOD=1e9+7;
const int inf=1e12;
const int mynum=21;
const int N=3e5;
const int siz=N+mynum;
const int int32=4294967295;
void solve(){ 
    int n,k;
    cin>>n>>k;
    int v[n+1],d[n+1];
    v[0]=0;
    d[0]=0;
    d[1]=0;
    for(int i=1;i<=n;i++){
        cin>>v[i];
        if(i>1)d[i]=v[i]-v[i-1];
    }
    sort(d,d+n+1);
    int ans=k;
    for(int i=2;i<=n-k+1;i++){
        ans+=d[i];
    }
    cout<<ans;
}  
signed main() {
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if(testcases)cin>>t;
    while(t--){
        solve();
    }
}
// 1 7 1 7 7 3 2 3
// 1 2 3 4 5 6 7 8
/*
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
------------------------------------------##+----------+##------------------------------------------
----------------------------------------+###------------###+----------------------------------------
--------------------------+###------------##------------##------------###+--------------------------
--------------------------+###+------#+#--##+--#+##+#---##--#+#-------###---------------------------
----------+---------------++-+###-----##++##+-+#-++-++-+##++##-----###+-++---------------+----------
----------+###+---------------####+##+#+##-#+--+#--#+--+#-##+####+####---------------+###+----------
---------#####+##++--------+++#######+---##++----+-----++##---+#######+++--------++##+#####---------
-----+#++##-######-##-------##++#####+----+##+--++----+##+----######++#+-------##-######-##++#+-----
--------#################-----+##+####---+++##--+++---##+++---####+##+-----#################--------
-------##---############-+++---####+##---++##---#++#---##++---##+####---+++-############---##-------
-------+-----##############+---######-+--+##+---##+#+--+##+--+-######---+##############-----#-------
-------+-##+--+#############+---+##++-#---#+----##+#+---+#---#-++##+---+#############+--+##-+-------
---------###---###+++#########---####-##-------+##+#+-------##-####---#########+++###---###---------
----------+###--+#######++######+--++-##+----+-###+##-+----+#+-++--+######++#######+--###+----------
----------+####---+###########++##++--+----+++####+###+-++------++##++###########+---####+----------
--------+##+####---+###############+--------###++++-+###--------+###############----####+##+--------
---------++###+##+--++---+++++++++++-#------+##-+##+-##+------#-+++++++++++----#--+##+###++---------
---------+-+#####+-+###############++-#+-----++-+###-++-----+#-+################+-+#####+-+---------
---------+#########+-+#----++++#######-##+---#+++##+++#---+##-#######++++----#+-+#########+---------
----------#++########+----#########+++#+--++####+#++#####+--+#+-+#########-----########++#----------
----------#---+#+######-----#+----+####-+++##+#+####+#+##+++-####+----+#-----######+#----++---------
---------#####-#####++#-#---------+++--######++#++++#+#######+++++---------#-#++#####-#####---------
----------++#####+-+###+##------+###+++#######+######+#######+++###+------##-###+-+#####++----------
----------++#--+#######++#------#++##+-+---#+##########+#+--+--##++#------##-#######+--#++----------
----------------#######+###----###+----------##########----------+###----###+#######----------------
----------------+#+####-###+---##-------------+###+##+--------+----##---+###-####+#+----------------
----------------+#-###+-+#+--+##---##+---++--##########--++---+##---##---+#+-+###-#+----------------
----------------+#--+###----+##---+#----###+-##########-+###----#+---##-----###+--#+----------------
----------------+#--+##----+##---+#+----+#--+##########---#+----+#+---##-----##---#+----------------
----------------+#---#-----##----#+-----+#--###########+--#+-----+#----##-----#---#+----------------
---------------------+----##+---##------#+--+##########+--+#------##---+##----+---------------------
---------------------+---##+---+#------+#-----########-----#+------#+---+##---+---------------------
---------------------+---##----#-------+#----+########+----#+-------#----##+--+---------------------
---------------------+---#----++-------+#-----########-----#+-------#+----#+--+---------------------
---------------------+---#----+---------#----+########-----#+-------++----+---+---------------------
---------------------+---#----+---------+-----########-----#+--------+----+---+---------------------
-------------------------#--------------+-----########-----+--------------#+------------------------
-------------------------+--------------+-----########-----+--------------+-------------------------
-------------------------#--------------------+#######--------------------#+------------------------
------------------------+#--------------------########--------------------#+------------------------
------------------+---#+##--------------------#######+--------------------##+#--++------------------
------------------###+####+#+--------------+#+#+####+++#+--------------+#+####+###------------------
-------------------##+####+#+-+#+----------###-+####+-###----------+#--+#+####+#+-------------------
--------------------########+##---------+##+-#--++#+--#-+##+--------+##+########--------------------
----------------+++++############+------+###--#------#--###+------+###########+++++-----------------
----------------+-----+-----++-+--+---+-+--##+##-+#-#++#+--+-#---+--+-++-----+-----+----------------
--------------------------------------+##+---###+##+###---+##+--------------------------------------
-----------------------------------------+###++#-+#-#+++##+-----------------------------------------
-------------------------------------------+++++-+#-++++--------------------------------------------
-------------------------------------++---+++++++++++++++++--++-------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

\\\\\\
Machine
I will cut you down
break you apart
splay the gore of your profane form across the stars
I will grind you down until the very sparks cry for mercy
My hands shall relish
Ending you
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...