Submission #964514

# Submission time Handle Problem Language Result Execution time Memory
964514 2024-04-17T04:56:59 Z UmairAhmadMirza Stove (JOI18_stove) C++17
100 / 100
47 ms 2412 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
int const N=2e5+5;
int const mod=1e9+7;

void solve(){
	int n,k;
	cin>>n>>k;
	k--;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	vector<int> d;
	int ans=1+(arr[n-1]-arr[0]);
	for(int i=0;i<n-1;i++)
		d.push_back((arr[i+1]-arr[i])-1);
	sort(d.begin(), d.end());
	reverse(d.begin(), d.end());
	for(int i=0;i<min(k,n-1);i++)
		ans-=d[i];
	cout<<ans<<endl;
}

int main(){
	int t=1;
	// cin>>t;
	while(t--)
		solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 472 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 2 ms 448 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 472 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 2 ms 448 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 47 ms 2200 KB Output is correct
17 Correct 36 ms 2412 KB Output is correct
18 Correct 36 ms 2252 KB Output is correct
19 Correct 41 ms 2252 KB Output is correct
20 Correct 44 ms 2360 KB Output is correct
21 Correct 43 ms 2252 KB Output is correct
22 Correct 43 ms 2408 KB Output is correct
23 Correct 35 ms 2252 KB Output is correct
24 Correct 36 ms 2312 KB Output is correct