Submission #202978

#TimeUsernameProblemLanguageResultExecution timeMemory
202978Harry464Stove (JOI18_stove)C++14
100 / 100
86 ms3312 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, m; cin >> n >> m; vector <long long> a(n); vector <long long> dif; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) if (a[i+1] - a[i] > 1) dif.push_back(a[i+1] - a[i] - 1); sort(dif.begin(),dif.end()); int s = dif.size(); long long suma = a[n-1] + 1 - a[0]; for (int i = 0; i < m - 1 && s - 1 - i >= 0; i++) suma -= dif[s - 1 - i]; cout << suma; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...