제출 #643495

#제출 시각아이디문제언어결과실행 시간메모리
643495GaLzStove (JOI18_stove)C++14
100 / 100
27 ms2272 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; const ll mod=1e9+7; const ll maxn=1e5+5; const int INF=1e9; #define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define fi first #define se second #define pb push_back #define ub upper_bound #define lb lower_bound #define endl '\n' int n, k, arr[maxn], ans; priority_queue<int> pq; int main() { ok cin >> n >> k; for(int i=0; i<n; i++) { cin >> arr[i]; } ans=arr[n-1]-arr[0]+1; for(int i=1; i<n; i++) { pq.push(arr[i]-arr[i-1]-1); } while(!pq.empty()) { if(k==1) break; ans-=pq.top(); pq.pop(); k--; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...