Submission #545508

# Submission time Handle Problem Language Result Execution time Memory
545508 2022-04-04T16:43:20 Z MohamedAliSaidane Stove (JOI18_stove) C++14
100 / 100
25 ms 3212 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

#define pb push_back
#define popb pop_back
#define pf push_front
#define popf pop_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second

int nx[4] = {0,0,1,-1}, ny[4] = {1,-1,0,0};
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);}

int n, k;
vll A;
void solve()
{
    cin >> n >> k;
    A.assign(n,0);
    for(int i = 0; i < n ; i ++)
        cin >> A[i];
    sort(all(A));
    vll B;
    for(int i = 0; i < n - 1; i ++)
        B.pb(A[i+1] - A[i]);
    sort(all(B));
    ll ans = n;
    for(int i = 1; i <= n - k; i ++)
        ans += B[i-1]-1;
    cout << ans ;

}

int main()
{
    ios::sync_with_stdio(false);
    int tt  = 1;
    while(tt--)
        solve();
}



# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 2 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 2 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 22 ms 2264 KB Output is correct
17 Correct 20 ms 3148 KB Output is correct
18 Correct 20 ms 3156 KB Output is correct
19 Correct 20 ms 3148 KB Output is correct
20 Correct 25 ms 3136 KB Output is correct
21 Correct 20 ms 3144 KB Output is correct
22 Correct 21 ms 3156 KB Output is correct
23 Correct 21 ms 3212 KB Output is correct
24 Correct 22 ms 3196 KB Output is correct