# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
195645 | 2020-01-16T16:58:07 Z | T0p_ | Stove (JOI18_stove) | C++14 | 35 ms | 3052 KB |
#include<bits/stdc++.h> using namespace std; #define pb push_back struct data{ int val, pos; bool operator < (const data & o) const{ return val > o.val; } }; int arr[100100], mark[100100]; vector<data> v; int main(){ int n, k; scanf(" %d %d",&n,&k); for(int i=1 ; i<=n ; i++) scanf(" %d",&arr[i]); if(k >= n){ printf("%d\n",n); return 0; } for(int i=2 ; i<=n ; i++) v.pb({arr[i] - arr[i-1], i}); sort(v.begin(), v.end()); k--; long long ans = 0; mark[1] = 1; for(int i=0 ; i<k ; i++) mark[v[i].pos] = 1; long long hval = arr[1]; for(int i=2 ; i<=n ; i++){ if(mark[i]){ ans += arr[i-1] - hval + 1; hval = arr[i]; } } ans += arr[n] - hval + 1; printf("%lld\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 400 KB | Output is correct |
2 | Correct | 2 ms | 248 KB | Output is correct |
3 | Correct | 3 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 3 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 1 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 400 KB | Output is correct |
2 | Correct | 2 ms | 248 KB | Output is correct |
3 | Correct | 3 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 3 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 1 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 252 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 3 ms | 376 KB | Output is correct |
12 | Correct | 3 ms | 376 KB | Output is correct |
13 | Correct | 1 ms | 392 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 400 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 400 KB | Output is correct |
2 | Correct | 2 ms | 248 KB | Output is correct |
3 | Correct | 3 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 3 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 1 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 252 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 3 ms | 376 KB | Output is correct |
12 | Correct | 3 ms | 376 KB | Output is correct |
13 | Correct | 1 ms | 392 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 400 KB | Output is correct |
16 | Correct | 31 ms | 2848 KB | Output is correct |
17 | Correct | 27 ms | 2900 KB | Output is correct |
18 | Correct | 35 ms | 2928 KB | Output is correct |
19 | Correct | 30 ms | 2924 KB | Output is correct |
20 | Correct | 31 ms | 3052 KB | Output is correct |
21 | Correct | 34 ms | 3024 KB | Output is correct |
22 | Correct | 31 ms | 3040 KB | Output is correct |
23 | Correct | 31 ms | 2872 KB | Output is correct |
24 | Correct | 25 ms | 3000 KB | Output is correct |