Submission #998161

#TimeUsernameProblemLanguageResultExecution timeMemory
998161spensaStove (JOI18_stove)C++17
100 / 100
31 ms6992 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define pii pair<int,int> #define FOR(i, a, b) for(int i=(signed)(a); i<=(signed)(b); i++) #define F0R(i, a) for(int i=(0); i<(signed)(a); i++) const int MXN = 1e5 + 10; ll T[MXN] = {0}; int main(){ //faster io ios_base::sync_with_stdio(false); cin.tie(NULL); ll N, K; cin>>N>>K; FOR(i, 1, N) cin>>T[i]; K--; ll ans = T[N] + 1 - T[1]; multiset<ll> st; FOR(i, 2, N){ st.insert(-(T[i]-T[i-1]-1)); } for(ll i: st){ if(K==0) break; ans+=i; K--; } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...