# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092456 |
2024-09-24T06:46:45 Z |
vjudge1 |
Stove (JOI18_stove) |
C++17 |
|
43 ms |
8444 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define stdI freopen("input.txt", "r", stdin);
#define stdO freopen("output.txt", "w", stdout);
#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define int long long
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,
null_type,less<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;
const int MAXN = 2e5 + 100, INF = 1e18, MOD = 1e9 + 7;
void solve()
{
vector<pii> v;
int n, k;
cin >> n >> k;
int a[n];
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a, a + n);
for(int i = 1; i < n; i++)
{
v.push_back(mp(a[i] - a[i - 1] - 2, i));
}
set<int> s; k--;
sort(all(v));
int ans = 0; s.insert(0);
while(v.size() > 0 && k > 0)
{
pii x = v.back(); v.pop_back(); k--;
ans += x.F;
s.insert(x.S);
}
cout << a[n - 1] + 2 - a[0] - s.size() - ans << "\n";
}
int32_t main()
{
IOS;
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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
18 ms |
4284 KB |
Output is correct |
17 |
Correct |
21 ms |
4312 KB |
Output is correct |
18 |
Correct |
18 ms |
4312 KB |
Output is correct |
19 |
Correct |
18 ms |
4312 KB |
Output is correct |
20 |
Correct |
28 ms |
6096 KB |
Output is correct |
21 |
Correct |
38 ms |
7884 KB |
Output is correct |
22 |
Correct |
41 ms |
8396 KB |
Output is correct |
23 |
Correct |
41 ms |
8396 KB |
Output is correct |
24 |
Correct |
43 ms |
8444 KB |
Output is correct |