제출 #1055440

#제출 시각아이디문제언어결과실행 시간메모리
1055440alex_2008Stove (JOI18_stove)C++14
100 / 100
15 ms2548 KiB
#include <iostream> #include <vector> #include <set> #include <map> #include <algorithm> #include <cmath> #include <queue> #include <string> using namespace std; typedef long long ll; const int N = 1e5 + 10; int a[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; k--; for (int i = 1; i <= n; i++) { cin >> a[i]; } int ans = a[n] - a[1] + 1; vector <int> v; for (int i = 1; i < n; i++) { v.push_back(a[i + 1] - a[i] - 1); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); for (int i = 0; i < k; i++) { ans -= v[i]; } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...