# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880987 | 2023-11-30T10:10:15 Z | theghostking | Stove (JOI18_stove) | C++17 | 56 ms | 5320 KB |
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n,k; cin >> n >> k; if (n==1){ cout << "1\n"; return 0; } int arr[n]; for (int i = 0; i<n; i++){ cin >> arr[i]; } sort(arr,arr+n); vector<bool> pres(n); pres[0] = true; priority_queue<pair<int,int>> pq; for (int i = 0; i<n-1; i++){ pq.push({arr[i+1]-arr[i],i}); } int kc = k; k--; while (k--){ pres[pq.top().second+1] = true; pq.pop(); } vector<int> nxt(n,-1); int tr = 0; for (int i = 1; i<n; i++){ if (pres[i]){ nxt[tr] = i-1; tr = i; } } int lst = arr[0]; int ind = 0; int ans = 0; for (int i = 0; i<n; i++){ if (pres[i]){ int nd = nxt[i]; if (nd == -1){ ans += (arr[n-1]-arr[i]+1); } else{ ans += (arr[nd]-arr[i]+1); } } } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 440 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 | 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 | 440 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 | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 488 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 604 KB | Output is correct |
15 | Correct | 2 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 | 440 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 | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 488 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 604 KB | Output is correct |
15 | Correct | 2 ms | 348 KB | Output is correct |
16 | Correct | 34 ms | 4388 KB | Output is correct |
17 | Correct | 34 ms | 4352 KB | Output is correct |
18 | Correct | 37 ms | 4392 KB | Output is correct |
19 | Correct | 34 ms | 5320 KB | Output is correct |
20 | Correct | 40 ms | 4380 KB | Output is correct |
21 | Correct | 44 ms | 4500 KB | Output is correct |
22 | Correct | 44 ms | 4292 KB | Output is correct |
23 | Correct | 45 ms | 4292 KB | Output is correct |
24 | Correct | 56 ms | 4292 KB | Output is correct |