답안 #687030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687030 2023-01-26T05:17:39 Z viwlesxq Stove (JOI18_stove) C++17
100 / 100
50 ms 3188 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 << 1;
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 308 KB Output is correct
11 Correct 2 ms 316 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 308 KB Output is correct
11 Correct 2 ms 316 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 49 ms 3164 KB Output is correct
17 Correct 49 ms 3140 KB Output is correct
18 Correct 49 ms 3092 KB Output is correct
19 Correct 47 ms 3084 KB Output is correct
20 Correct 45 ms 3088 KB Output is correct
21 Correct 50 ms 3188 KB Output is correct
22 Correct 49 ms 3084 KB Output is correct
23 Correct 46 ms 3080 KB Output is correct
24 Correct 45 ms 3096 KB Output is correct