Submission #654262

# Submission time Handle Problem Language Result Execution time Memory
654262 2022-10-30T17:48:58 Z hail Stove (JOI18_stove) C++17
100 / 100
22 ms 3268 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long 
#define pi pair<int, int>
#define mp make_pair
#define ld long double

const int MOD = 7 + (int)1e9;
const int INF = (int)1e18;

//

void solve()
{
    int n, k;
    cin>>n>>k;

    vector<int> t(n+1, 0);
    for(int i=1; i<=n; i++)
    {
        cin>>t[i];
    }

    sort(t.begin()+1, t.end());

    vector<int> d(0);
    int tot = t.back() + 1 - t[1];

    for(int i=1; i<n; i++)
    {
        d.pb(t[i+1] - t[i] - 1);
    }

    sort(d.begin(), d.end());

    int cnt = 1;
    while(cnt<k && (not d.empty()))
    {
        tot -= d.back();
        //cerr<<d.back()<<"\n";
        d.pop_back();
        cnt++;
    }

    cout<<tot;
}

signed main()
{
    fast_io;

    int t=1; 
    //cin>>t;
    while(t--)
    {
        solve();
    }
    cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 3268 KB Output is correct
17 Correct 19 ms 3156 KB Output is correct
18 Correct 20 ms 3148 KB Output is correct
19 Correct 21 ms 3100 KB Output is correct
20 Correct 22 ms 3152 KB Output is correct
21 Correct 19 ms 3232 KB Output is correct
22 Correct 20 ms 3224 KB Output is correct
23 Correct 18 ms 3148 KB Output is correct
24 Correct 19 ms 3220 KB Output is correct