Submission #487962

# Submission time Handle Problem Language Result Execution time Memory
487962 2021-11-17T08:46:09 Z BY_KUTBILIM Stove (JOI18_stove) C++17
100 / 100
20 ms 2840 KB
/*
  @AUTHOR: BY_KUTBILIM
  FILE CREATED: 17.11.2021 14:43:09  (GMT+6)
*/
#include <bits/stdc++.h>
using namespace std;

#define endl      '\n'
#define sz(x)     int((x).size())
#define all(x)    (x).begin(), (x).end()
#define rall(x)   (x).rbegin(), (x).rend()
#define fi        first
#define se        second
#define pb        push_back
using ll = long long;
using pii = pair<int, int>;

void solve(){
	int n, k;
	cin >> n >> k;
	long long a[n];
	for(auto &e : a){
		cin >> e;
	}
	long long b[n-1];
	for(int i = 0; i < n-1; i++){
		b[i] = a[i+1] - a[i]-1;
	}
	sort(b, b + n - 1);
	long long ans = n;
	for(int i = 0; i <n-k; i++)ans += b[i];
	cout << ans << endl;
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 20 ms 2840 KB Output is correct
17 Correct 16 ms 2356 KB Output is correct
18 Correct 17 ms 2372 KB Output is correct
19 Correct 17 ms 2764 KB Output is correct
20 Correct 17 ms 2756 KB Output is correct
21 Correct 16 ms 2740 KB Output is correct
22 Correct 16 ms 2736 KB Output is correct
23 Correct 18 ms 2832 KB Output is correct
24 Correct 16 ms 2764 KB Output is correct