#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
//-----------------------
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mem(f,x) memset(f, x, sizeof(f))
#define __lcm(a, b) (1ll * a * b) / __gcd(a, b)
#define bit(mask, i) ((mask >> i) & 1)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define el '\n'
#define F first
#define S second
#define io(x) freopen(x".inp","r",stdin),freopen(x".out","w",stdout)
//-----------------------
const ll INF = 1e18;
const int MOD = 1e9 + 7;
const int MULTI = 0;
const int dx[4] = {0, 0, 1, -1}; //R L D U
const int dy[4] = {1, -1, 0, 0};
//-----AUTHOR trvhung VNG High School for Gifted Student-----
const int maxn = 2e5 + 5;
int n, k, a[maxn];
bool cmp(int x, int y) {
return x > y;
}
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; ++i)
cin >> a[i];
vector<int> v;
for (int i = 2; i <= n; ++i)
v.pb(a[i] - a[i - 1] - 1);
sort(v.begin(), v.end(), cmp);
int ans = a[n] - a[1] + 1;
for (int i = 0; i < k - 1; ++i) ans -= v[i];
cout << ans << el;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (!MULTI) solve();
else {
int test; cin >> test;
while (test--) solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
16 ms |
2268 KB |
Output is correct |
17 |
Correct |
17 ms |
2412 KB |
Output is correct |
18 |
Correct |
16 ms |
2272 KB |
Output is correct |
19 |
Correct |
16 ms |
2268 KB |
Output is correct |
20 |
Correct |
17 ms |
2272 KB |
Output is correct |
21 |
Correct |
16 ms |
2348 KB |
Output is correct |
22 |
Correct |
16 ms |
2272 KB |
Output is correct |
23 |
Correct |
17 ms |
2268 KB |
Output is correct |
24 |
Correct |
17 ms |
2296 KB |
Output is correct |