답안 #969498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969498 2024-04-25T08:38:21 Z crazycoder00 Stove (JOI18_stove) C++17
100 / 100
17 ms 2468 KB
#include <bits/stdc++.h>
using namespace std;

// Templates
// ==============================================
    // Debugging
    #ifdef LOCAL
    #include "debug.h"
    #else
    #define debug(...)
    #endif

    typedef long long ll;
    typedef vector<int> VI;
    typedef vector<long long> VLL;
    typedef vector<bool> VB;
    typedef vector<vector<int>> VVI;
    typedef pair<int, int> PI;
    typedef pair<ll, ll> PLL;
    typedef vector<pair<int, int>> VPI;
    #define pb push_back
    #define ff first
    #define ss second
    #define loop(i, s, e) for (int i = s; i < e; ++i)
    #define inp(v) for (auto& x : v) cin >> x
    #define all(a) a.begin(), a.end()
    #define revall(a) a.rbegin(), a.rend()
    #define nl "\n"
    // #define MOD 998244353
    #define MOD 1000000007
    #define MAXN 300002
    #define INF (int) 1e9
    #define INFL (ll) 1e18
    #define yep cout << "YES\n"
    #define nope cout << "NO\n"
// ==============================================

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

    VI interval;
    loop(i, 1, n) interval.pb(a[i] - a[i - 1] - 1);
    sort(revall(interval));

    int ans = a[n - 1] - a[0] + 1;
    loop(i, 0, k - 1) ans -= interval[i];

    cout << ans << nl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t;
    while(t--) solve();

    #ifdef LOCAL
    cerr << "Execution time: " << 1000.f * clock() / CLOCKS_PER_SEC << " ms." << nl;
    #endif

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 17 ms 2272 KB Output is correct
17 Correct 14 ms 2392 KB Output is correct
18 Correct 14 ms 2268 KB Output is correct
19 Correct 15 ms 2388 KB Output is correct
20 Correct 14 ms 2272 KB Output is correct
21 Correct 14 ms 2272 KB Output is correct
22 Correct 15 ms 2392 KB Output is correct
23 Correct 14 ms 2468 KB Output is correct
24 Correct 15 ms 2272 KB Output is correct