Submission #868911

#TimeUsernameProblemLanguageResultExecution timeMemory
868911rockstarStove (JOI18_stove)C++17
100 / 100
16 ms2904 KiB
// #pragma GCC optimize("O3,unroll-loops,inline,no-stack-protector") // #pragma GCC target("avx,avx2,sse3,ssse3,sse4.1,sse4.2,fma,bmi2,abm,popcnt,mmx,tune=native") #include <bits/stdc++.h> using namespace std; #define trace(x) cerr << #x << ": " << (x) << endl; #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; #define int ll constexpr int INF = numeric_limits<int>::max() / 2; void solve() { int n, k; cin >> n >> k; vector<int> t(n); for (int& i : t) cin >> i; vector<int> diff(n - 1); for (int i = 1; i < n; ++i) diff[i - 1] = t[i] - t[i - 1]; sort(all(diff)); int ans = 0; for (int i = 0; i <= n - 1 - k; ++i) ans += diff[i]; cout << ans + k; } signed main() { #ifdef LOCAL freopen("input.in", "r", stdin); #else ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif int t = 1; // cin >> t; while (t--) solve(); #ifdef LOCAL cerr << '\n' << "time = " << clock() * 1.0 / CLOCKS_PER_SEC << '\n'; #endif return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...