답안 #784896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784896 2023-07-16T17:35:54 Z fanwen Stove (JOI18_stove) C++17
100 / 100
35 ms 6460 KB
/**
 *      author : pham van sam 
 *      created : 17 July 2023 (Monday)
 **/

#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

void you_make_it(void);

signed main() {

    #define TASK "stove"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    auto start_time = chrono::steady_clock::now();

    int test = 1;
    // cin >> test;
    for (int i = 1; i <= test; ++i) {
        you_make_it();
        // cout << '\n';
    }

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

const int MAXN = 1e5 + 5;

int N, K, T[MAXN];

void you_make_it() {
    cin >> N >> K;
    FOR(i, 1, N) cin >> T[i];
    multiset <int> s;
    FOR(i, 2, N) {
        s.insert(T[i] - T[i - 1]);
    }
    int ans = 0;
    REP(i, N - K) {
        ans += (*s.begin()) - 1;
        s.erase(s.begin());
    }
    cout << ans + N;
}

// Dream it. Wish it. Do it.

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 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 332 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 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 332 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 1 ms 476 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 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 332 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 1 ms 476 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 32 ms 6460 KB Output is correct
17 Correct 29 ms 6340 KB Output is correct
18 Correct 28 ms 6268 KB Output is correct
19 Correct 33 ms 6348 KB Output is correct
20 Correct 27 ms 6268 KB Output is correct
21 Correct 28 ms 6272 KB Output is correct
22 Correct 27 ms 6240 KB Output is correct
23 Correct 35 ms 6240 KB Output is correct
24 Correct 27 ms 6252 KB Output is correct