제출 #1228875

#제출 시각아이디문제언어결과실행 시간메모리
1228875ghgcdcStove (JOI18_stove)C++17
100 / 100
13 ms1608 KiB
#include<bits/stdc++.h> using namespace std; const int N = 100001; int a[N], b[N], gap[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n; long long k;cin>>n>>k; for(int i = 0; i < n; ++i)cin>>a[i]; sort(a, a + n); int m = 0; b[m++] = a[0]; for(int i = 1; i < n; ++i){ if(a[i] != a[i - 1]){ b[m++] = a[i]; } } if(k >= m){ cout<<m<<'\n'; return 0; } long long res = m; for(int i = 0; i < m - 1; ++i)gap[i] = b[i + 1] -(b[i] + 1); sort(gap, gap + m - 1); int need = m - k; for(int i = 0; i < need; ++i)res += gap[i]; cout<<res<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...