Submission #45659

#TimeUsernameProblemLanguageResultExecution timeMemory
45659realityStove (JOI18_stove)C++17
100 / 100
101 ms10656 KiB
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} int main(void) { int n,k; cin>>n>>k; vi s(n); for (auto & it : s) cin>>it; int ans = s.back() - s[0] + 1; vi v; --k; for (int i = 1;i < n;++i) v.pb(s[i] - s[i - 1] - 1); sort(all(v),greater < int > ()); for (int i = 0;i < k;++i) ans -= v[i]; cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...