# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
901517 | VinhLuu | Stove (JOI18_stove) | C++17 | 16 ms | 3772 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.
// happy
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define int long long
//#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 2e5 + 5;
const int oo = 1e16;
const int mod = 1e9 + 7;
const int base = 29; // >= so pt pb max
int n, a[N], b[N], sum, k;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n >> k;
for(int i = 1; i <= n; i ++){
cin >> a[i];
}
for(int i = 1; i < n; i ++){
b[i] = a[i + 1] - a[i] - 1;
sum += (a[i + 1] - a[i] - 1);
}
// cout << sum << "\n";
sort(b + 1, b + n, greater<int>());
for(int i = 1; i <= min(n - 1, k - 1); i ++){
// cout << b[i] << "\n";
sum -= b[i];
}
cout << sum + n;
}
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... |