Submission #315252

# Submission time Handle Problem Language Result Execution time Memory
315252 2020-10-22T06:39:35 Z Jarif_Rahman Stove (JOI18_stove) C++17
100 / 100
28 ms 2796 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k; cin >> n >> k;
    ll mn = 1e18, mx = -1e18;;
    vector <ll> v(n);
    for(ll &x: v){
        cin >> x;
        mn = min(mn, x);
        mx = max(mx, x);
    }
    if(k >= n){
        cout << n << "\n";
        exit(0);
    }
    ll ans = mx - mn + 1;
    priority_queue<int> pq;
    for(int i = 0; i < n - 1; i++) pq.push(v[i+1]-v[i]-1);
    k--;
    while(k--) ans-= pq.top(), pq.pop();
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 15 ms 2708 KB Output is correct
17 Correct 15 ms 2796 KB Output is correct
18 Correct 15 ms 2688 KB Output is correct
19 Correct 20 ms 2688 KB Output is correct
20 Correct 21 ms 2688 KB Output is correct
21 Correct 28 ms 2688 KB Output is correct
22 Correct 27 ms 2688 KB Output is correct
23 Correct 27 ms 2688 KB Output is correct
24 Correct 27 ms 2688 KB Output is correct