Submission #547941

# Submission time Handle Problem Language Result Execution time Memory
547941 2022-04-12T04:03:33 Z Aktan Stove (JOI18_stove) C++14
100 / 100
76 ms 8516 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define ft first
#define sc second
const int mod=1e9+7,INF=1e17,N=1e5;

map<int,int> m;
multiset<int> s;
main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	for(int i=1;i<n;i++){
		s.insert(a[i]-a[i-1]);
	}
	int cnt=1,sum=0;
	while(!s.empty() && k>cnt){
		m[*--s.end()]++;
		s.erase(s.find(*--s.end()));
		cnt++;
	}
	int l=0;
	for(int i=0;i<n-1;i++){
		if(m[a[i+1]-a[i]]!=0){
			m[a[i+1]-a[i]]--;
			sum+=((a[i]-a[l])+1);
			l=i+1;
		}
	}
	sum+=a[n-1]-a[l]+1;
	cout << sum;
}

Compilation message

stove.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 628 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 628 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 55 ms 8468 KB Output is correct
17 Correct 55 ms 8516 KB Output is correct
18 Correct 53 ms 8472 KB Output is correct
19 Correct 56 ms 8472 KB Output is correct
20 Correct 66 ms 7440 KB Output is correct
21 Correct 73 ms 7496 KB Output is correct
22 Correct 76 ms 7388 KB Output is correct
23 Correct 72 ms 7364 KB Output is correct
24 Correct 74 ms 7376 KB Output is correct