Submission #70602

#TimeUsernameProblemLanguageResultExecution timeMemory
70602someone_aaStove (JOI18_stove)C++17
100 / 100
73 ms11004 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int maxn = 100100; int arr[maxn], n, k; bool light[maxn]; vector<pair<int,int> > diff; int main() { cin>>n>>k; for(int i=1;i<=n;i++) { cin>>arr[i]; } for(int i=2;i<=n;i++) { diff.pb(mp(arr[i]-arr[i-1], i)); } light[1] = true; sort(diff.rbegin(), diff.rend()); for(int i=0;i<k-1;i++) { light[diff[i].second] = true; } arr[0] = 0; int last = 1; int result = 0; for(int i=1;i<=n;i++) { if(light[i]) { result += arr[i-1] + 1 - last; last = arr[i]; } else continue; } result += arr[n] + 1 - last; cout<<result; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...