Submission #1105873

# Submission time Handle Problem Language Result Execution time Memory
1105873 2024-10-28T07:43:49 Z abushbandit_ Stove (JOI18_stove) C++17
100 / 100
17 ms 3448 KB
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back

template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }

const int inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 1;

void solve(){
	
	int n,k;
	cin >> n >> k;
	int t[n];
	for(int i = 0;i < n;i++) {
		cin >> t[i];
	}
	//~ int ans = 0;
	vector<int> v;
	for(int i = 0;i < n - 1;i++) {
		v.pb(t[i + 1] - t[i] - 1);
	}
	sort(all(v));
	int ans = n;
	for(int i = 0;i < n - k;i++) {
		ans += v[i];
	}
	cout << ans << "\n";
	
	
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);cout.tie(nullptr);
	int T = 1;
	//~ cin >> T;
	while(T--) {
		solve();
	}
	
}
	
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 16 ms 3280 KB Output is correct
17 Correct 15 ms 3280 KB Output is correct
18 Correct 16 ms 3264 KB Output is correct
19 Correct 16 ms 3280 KB Output is correct
20 Correct 16 ms 3280 KB Output is correct
21 Correct 17 ms 3448 KB Output is correct
22 Correct 17 ms 3280 KB Output is correct
23 Correct 16 ms 3136 KB Output is correct
24 Correct 15 ms 3280 KB Output is correct