Submission #687029

# Submission time Handle Problem Language Result Execution time Memory
687029 2023-01-26T05:17:17 Z viwlesxq Stove (JOI18_stove) C++17
0 / 100
1 ms 300 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef int64_t ll;
typedef string str;
 
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
 
signed main() {
	int n, k;
	cin >> n >> k;
	ll a[n], ans = 0;
	for (int i = 0; i < n; i++) cin >> a[i];
	if (n == 1) {
		cout << 2;
		return 0;
	}
	sort(a, a + n);
	ans = a[n - 1] - a[0] + 1;
	vector <ll> diff;
	for (int i = 1; i < n; i++) {
		diff.pb(a[i] - a[i - 1]);
	}
	k--;
	sort(all(diff));
	while (k && !diff.empty()) {
		k--;
		ans -= diff.back() - 1;
		diff.ppb();
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -