답안 #678028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678028 2023-01-05T04:08:02 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
20 ms 3008 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define PI 3.141592653589793238

using namespace std;

ll binpow (ll a, ll b){
    if (b == 0) return 1;
    if (b & 1) return binpow(a, b - 1) * a;
    else return binpow(a, b / 2) * binpow(a, b / 2);
}
ll gcd(ll a, ll b){
    return (b ? gcd(b, a % b) : a);
}
ll nums(ll g){
    ll cur = 0;
    while(g){
        cur++, g /= 10;
    }

    return cur;
}

bool comp(vector <pair <ll, ll> > a, vector <pair <ll, ll> > b){
    return a.size() < b.size();
}

ll get1(ll q, ll g){
    ll cur = 1;

    for (ll i = q; i > g; i--){
        cur *= i;
    }

    return cur;
}

const ll mod = (ll)998244353;

ll n, k, t = 1, a[200005], p[200005];

vector <ll> v;

string s;

ll dp[500][500];

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    //freopen("success.in", "r", stdin);
    //freopen("success.out", "w", stdout);

    cin >> n >> k;

    ll mn = (ll)1e15, mx = 0;

    for (ll i = 1; i <= n; i++){
        cin >> a[i];

        if (i > 1) v.pb(abs(a[i] - a[i - 1]));

        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
    }

    ll ans = mx - mn + 1;

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

    ll cur = v.size() - 1;

    while(cur >= 0 && k > 1){
        ans -= (v[cur] - 1);

        cur--;
        k--;
    }

    cout << ans;

    return 0;
}

/**

4 16

10100

20
00101
10100

24



*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 400 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 348 KB Output is correct
14 Correct 2 ms 400 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 400 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 348 KB Output is correct
14 Correct 2 ms 400 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 2932 KB Output is correct
17 Correct 17 ms 2968 KB Output is correct
18 Correct 16 ms 2992 KB Output is correct
19 Correct 17 ms 2900 KB Output is correct
20 Correct 17 ms 2900 KB Output is correct
21 Correct 17 ms 2888 KB Output is correct
22 Correct 17 ms 3008 KB Output is correct
23 Correct 17 ms 2900 KB Output is correct
24 Correct 17 ms 2940 KB Output is correct