Submission #1053574

# Submission time Handle Problem Language Result Execution time Memory
1053574 2024-08-11T13:27:12 Z NAMIN Stove (JOI18_stove) C++14
100 / 100
17 ms 2464 KB
/*
ID: NAMIN
TASK:
LANG: C++
*/
#include <iostream>
#include <numeric>
#include <math.h>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <fstream>
#include <map>
#include <unordered_map>
#include <iomanip>

#define gcd __gcd
#define endl "\n"
#define ll long long

using namespace std;


void solve(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,k;
	cin >> n >> k;
	vector<int> visit(n);
	for(int i=0;i<n;i++)
		cin >> visit[i];

	sort(visit.begin(),visit.end());
	int T = visit[n-1]-visit[0]+1;

	priority_queue<int> q;

	for(int i=0;i<n-1;i++){
		q.push(visit[i+1]-visit[i]-1);
	}

	for(int i=0;i<k-1;i++){
		T -= q.top();
		q.pop();
	}

	cout << T << endl;
}

int main(){
	int t = 1;
	while(t--){
	 	solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 8 ms 2272 KB Output is correct
17 Correct 8 ms 2272 KB Output is correct
18 Correct 11 ms 2464 KB Output is correct
19 Correct 13 ms 2272 KB Output is correct
20 Correct 15 ms 2384 KB Output is correct
21 Correct 15 ms 2272 KB Output is correct
22 Correct 15 ms 2384 KB Output is correct
23 Correct 16 ms 2272 KB Output is correct
24 Correct 17 ms 2272 KB Output is correct