제출 #984916

#제출 시각아이디문제언어결과실행 시간메모리
984916normankr07Stove (JOI18_stove)C++17
100 / 100
15 ms3304 KiB
#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';
    }
}

컴파일 시 표준 에러 (stderr) 메시지

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...