# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033611 | cowwycow | Stove (JOI18_stove) | C++14 | 21 ms | 3868 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define name "aaaaaa"
using ll = long long;
using pll = pair<ll, ll>;
using ld = long double;
void file(){
ios_base::sync_with_stdio(0); cin.tie(0);
if(fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
}
const int maxn = 1e6 + 5;
ll a[maxn];
vector<ll> sus;
void solve (){
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 2; i <= n; i++){
sus.push_back({a[i] - a[i - 1] - 1});
}
sort(sus.begin(), sus.end(), greater<ll>());
ll ans = a[n] - a[1] + 1;
for(int i = 0; i < k - 1; i++){
ans -= sus[i];
}
cout << ans;
}
int main(){
file();
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |