Submission #312421

#TimeUsernameProblemLanguageResultExecution timeMemory
312421KarliverStove (JOI18_stove)C++14
100 / 100
20 ms1792 KiB
#include <bits/stdc++.h> #define FIXED_FLOAT(x) std::fixed <<std::setprecision(7)<<(x) #define all(v) (v).begin(), (v).end() using namespace std; #define loop(i,a,b) for (int i=a; i<b; ++i) using ll = long long; const int mod = 998244353; typedef pair<int , int> pairs; typedef complex<ll> G; const int N = 1e3 + 5; int power(int a,int b){ if(!b) return 1; int c=power(a,b/2); c=(1LL*c*c)%mod; if(b%2) c=(1LL*c*a)%mod; return c; } void done() { } /*string solve_palindrome(const string& s) { string a = s; reverse(a.begin(), a.end()); //a = s + "#" + a; int c = 0; for (int i = 1; i < (int)a.size(); i++) { while (c != 0 && a[c] != a[i]) c = pref[c - 1]; if (a[c] == a[i]) c++; pref[i] = c; } return s.substr(0, c); } */ /*3 3 7 7 9 11 4 6 6 7*/ void solve() { int n, k; cin >> n >> k; int a[n]; for(int i = 0;i < n;++i) { cin >> a[i]; } for(int i = n - 1;i > 0;--i) { a[i] -= a[i - 1] + 1; } sort(a + 1,a + n); ll ans = n; for(int i = 1;i <= n-k;++i) { ans += a[i]; } cout << ans << '\n'; } void another() { } void test_case() { int t; cin >> t; while(t--)another(); } int main() { ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...