# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
976091 |
2024-05-06T07:27:13 Z |
wood |
Stove (JOI18_stove) |
C++17 |
|
20 ms |
2492 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vp32 vector<p32>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
fast_cin();
#ifndef ONLINE_JUDGE
#ifdef _WIN32
freopen("input.in", "r", stdin);
freopen("input.out", "w", stdout);
#endif
#endif
int n,k; cin>>n>>k;
k--;
int arr [n];
for(int & sub : arr){
cin>>sub;
}
sort(arr,arr+n);
priority_queue<int> q;
for (size_t i = 1; i < n; i++)
q.push(arr[i]-arr[i-1]-1);
int res = arr[n-1]-arr[0]+1;
while(k--){
res-=q.top();
q.pop();
}
cout<<res<<'\n';
return 0;
}
Compilation message
stove.cpp: In function 'int main()':
stove.cpp:39:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
39 | for (size_t i = 1; i < n; i++)
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
11 ms |
2316 KB |
Output is correct |
17 |
Correct |
14 ms |
2492 KB |
Output is correct |
18 |
Correct |
11 ms |
2272 KB |
Output is correct |
19 |
Correct |
12 ms |
2272 KB |
Output is correct |
20 |
Correct |
15 ms |
2448 KB |
Output is correct |
21 |
Correct |
20 ms |
2272 KB |
Output is correct |
22 |
Correct |
20 ms |
2268 KB |
Output is correct |
23 |
Correct |
20 ms |
2240 KB |
Output is correct |
24 |
Correct |
20 ms |
2272 KB |
Output is correct |