답안 #984916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984916 2024-05-17T08:17:06 Z normankr07 Stove (JOI18_stove) C++17
100 / 100
15 ms 3304 KB
#define taskname ""
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifndef LOCAL
#define cerr \
    if (0)   \
    cerr
#endif

const bool multitest = 0;

const int MAXN = 2e5;
ll t[MAXN];

void solve()
{
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> t[i];
    }
    // Goal, minimize total turned on time
    // Active time = t[n] - t[1];
    // Got k time -> find the most k diff time to turn off;
    vector<ll> diff;
    ll sum = t[n] - t[1] + 1;
    for (int i = 2; i <= n; i++)
    {
        diff.push_back(t[i] - t[i - 1]);
    }
    sort(diff.begin(), diff.end());
    while (k-- > 1 && diff.size())
    {
        sum -= (diff.back() - 1);
        diff.pop_back();
    }
    cout << sum;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(taskname ".inp", "r"))
    {
        freopen(taskname ".inp", "r", stdin);
        freopen(taskname ".out", "w", stdout);
    }
    int tc = 1;
    if (multitest)
        cin >> tc;
    while (tc--)
    {
        solve();
        cout << '\n';
    }
}

Compilation message

stove.cpp: In function 'int32_t main()':
stove.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 600 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 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 600 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 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
16 Correct 14 ms 3292 KB Output is correct
17 Correct 15 ms 3292 KB Output is correct
18 Correct 14 ms 3292 KB Output is correct
19 Correct 15 ms 3292 KB Output is correct
20 Correct 15 ms 3292 KB Output is correct
21 Correct 15 ms 3288 KB Output is correct
22 Correct 15 ms 3292 KB Output is correct
23 Correct 15 ms 3292 KB Output is correct
24 Correct 15 ms 3304 KB Output is correct