Submission #212962

#TimeUsernameProblemLanguageResultExecution timeMemory
212962Coroian_DavidStove (JOI18_stove)C++11
100 / 100
73 ms2044 KiB
#include <iostream> #include <algorithm> #define MAX_N 100000 using namespace std; int n, k; int v[MAX_N + 1]; int d[MAX_N + 1]; int rez; void readFile() { cin >> n >> k; for(int i = 1; i <= n; i ++) cin >> v[i]; } void solve() { for(int i = 1; i < n; i ++) d[i] = abs(v[i] - v[i + 1]); sort(d + 1, d + n, greater<int>()); rez = min(n, k); for(int i = k; i <= n; i ++) rez += d[i]; } void printFile() { cout << rez << "\n"; } int main() { readFile(); solve(); printFile(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...