제출 #1256658

#제출 시각아이디문제언어결과실행 시간메모리
1256658tisin23Stove (JOI18_stove)C++20
0 / 100
0 ms328 KiB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;

long long fpow(long long a, long long b)
{
    long long res = 1;
    if (!b)
        return 1;
    while (b)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

#define ll signed long long
#define ull unsigned long long
#define endl '\n'
#define F first
#define S second
#define mp make_pair
#define triple(T1, T2, T3) pair<T1, pair<T2, T3>>
#define mt(a, b, c) mp(a, mp(b, c))
#define L first
#define M second.first
#define R second.second
#define pb push_back
#define ins insert
#define pq priority_queue
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define erray array
#define INF ((long long)1e18 + 7)
#define TEST(t) \
    ll t;       \
    cin >> t;   \
    while (t--)
#define has(vect, item) (find(vect.begin(), vect.end(), item) != vect.end())
#define forl(i, l, r) for (ll i = (l); i <= (r); i++)
#define forr(i, l, r) for (ll i = (r); i >= (l); i--)
#define kosokuIO                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout << fixed << setprecision(5)
#define ceilbin(N) (1 << (ll)(ceil(log2((double)N))))
#define v vector

// R = 0, U = 1, L = 2, D = 3
ll dx[4] = { 1, 0, -1, 0 };
ll dy[4] = { 0, 1, 0, -1 };
ll dk[8][2] = { 
    {2, 1},
    {-2, 1},
    {2, -1},
    {-2, -1},
    {1, 2},
    {-1, 2},
    {1, -2},
    {-1, -2},
 };
string stepDir = "URDL";

int main()
{
    kosokuIO;
    ll n, k;
    cin >> n >> k;
    v<ll> a(n);
    forl(i, 0, n-1)
    {
        cin >> a[i];
    }
    v<ll> b;
    forl(i, 0, n-2)
    {
        b.pb(a[i+1] - a[i]);
    }
    sort(b.rbegin(), b.rend());
    sort(a.begin(), a.end());
    // cout << "DEBUG" << endl;
    // forl(i, 0, n-2)
    // {
    //     cout << b[i] << " ";
    // }
    // cout << endl << "DEBUG" << endl;
    ll t = k;
    forl(i, k-1, n-1)
    {
        t += b[i];
    }
    cout << t << endl;
    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...