This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define el '\n'
#define pb push_back
#define mp make_pair
#define niggers \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define file(name) \
freopen(name ".inp", "r", stdin); \
freopen(name ".out", "w", stdout);
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const int mxN = 1e2 + 5;
const int mxM = 1e3 + 5;
const int N = 2e5 + 5;
int hx[] = {-1, 0, 1, 0};
int hy[] = {0, 1, 0, -1};
int main()
{
// freopen("b.inp", "r", stdin);
// freopen("b.out", "w", stdout);
ll pinkkiu = 1;
// cin >> pinkkiu;
while (pinkkiu--)
{
ll n, k;
cin >> n >> k;
k--;
vector<ll> v;
ll x;
cin >> x;
ll last = 0, fifi = x;
for (ll i = 2; i <= n; i++)
{
ll xx;
cin >> xx;
v.pb(xx - x - 1);
x = last = xx;
}
sort(v.begin(), v.end());
ll ans = last - fifi + 1;
while (k--)
{
ans -= max(0LL, v.back());
v.pop_back();
}
cout << ans;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |