# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1150477 | nguyn | Stove (JOI18_stove) | C++20 | 11 ms | 1096 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 1e5 + 5;
const int inf = 2e9;
int n, k;
int a[N];
int d[N];
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int res = a[n] + 1 - a[1];
for (int i = 2; i <= n; i++) {
d[i] = a[i] - a[i - 1];
}
sort(d + 2, d + 1 + n, greater<int>());
for (int i = 2; i <= k; i++) {
res = res - d[i] + 1;
}
cout << res;
}
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... |