# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1241803 | trinm01 | Stove (JOI18_stove) | C++20 | 12 ms | 1864 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>
const ll mod = 1e7 + 1203;
const ll MAXN = 3e5 + 5;
const ll oo = 1e18;
const ll base = 320;
int n, k, a[MAXN], b[MAXN];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("board.INP", "r"))
{
freopen("board.INP", "r", stdin);
freopen("board.OUT", "w", stdout);
}
cin >> n >> k;
FOR(i, 1, n){
cin >> a[i];
if(i!=1){
b[i]=a[i]-a[i-1]-1;
}
}
sort(b+1, b+1+n);
reverse(b+1, b+1+n);
int ans=a[n]+1-a[1];
FOR(i, 1, k-1){
ans-=b[i];
}
cout << ans;
return 0;
}
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... |