제출 #997287

#제출 시각아이디문제언어결과실행 시간메모리
997287IcelastStove (JOI18_stove)C++17
100 / 100
16 ms3544 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; void solve(){ ll n, k; cin >> n >> k; vector<ll> a(n+1), b; for(int i = 1; i <= n; i++){ cin >> a[i]; } ll ans = a[n]-a[1]+1; for(int i = 2; i <= n; i++){ b.push_back(a[i]-a[i-1]-1); } k--; sort(b.begin(), b.end(), greater<ll>()); for(int i = 0; i < k; i++){ ans -= b[i]; } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...