Submission #437171

#TimeUsernameProblemLanguageResultExecution timeMemory
437171skybergStove (JOI18_stove)C++17
100 / 100
77 ms2364 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<long long int>d; bool comp(long long int a,long long int b){ return a > b; } int main() { long long int n, k; long long int sumd; cin >> n >> k; long long int a; cin >> a; sumd = a; long long int b = a; for(int i = 1; i < n; i++){ cin >> b; d.push_back(b - a - 1); a = b; } sumd = b + 1 - sumd; sort(d.begin(), d.end(), comp); for(int i = 0; i < min((long long)d.size(),k - 1); i++){ sumd -= d[i]; } cout << sumd; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...