Submission #958821

#TimeUsernameProblemLanguageResultExecution timeMemory
958821sopaconkStove (JOI18_stove)C++17
100 / 100
20 ms2520 KiB
/* Sopaconk 6/04/23 */ #include <bits/stdc++.h> #define f first #define s second #define pb push_back #define deb(x) cout<<#x<<": "<<(x)<<endl using lli=long long int; //using pii=pair<int,int>; using ld=long double; lli MOD=1e9+7; using namespace std; #define endl '\n' void solve(){ lli n,k; cin>>n>>k; vector<lli> v (n); for(lli i=0; i<n; ++i){ cin>>v[i]; } lli aux=n; priority_queue<lli, vector<lli>, greater<lli>> pq; for(lli i=1; i<n; ++i){ pq.push(v[i]-v[i-1]-1); } lli ans=n; while(aux>k){ ans+=pq.top(); pq.pop(); aux--; } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...