Submission #1298779

#TimeUsernameProblemLanguageResultExecution timeMemory
1298779daotuankhoiStove (JOI18_stove)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }

const int MAXN = 1e5 + 5;
ll t[MAXN];

int main() {
    #define NAME "test"
    if (fopen(NAME".inp", "r")) {
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k; cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
    }
    vector<ll> v;
    for (int i = 1; i < n; i++) {
        v.emplace_back(t[i + 1] - t[i] - 1);
    }
    ll ans = 0;
    sort(v.begin(), v.end(), greater<ll>());
    for (int i = 1; i < k; i++) {
        ans += v[i];
    }
    cout << t[n] - t[1] - ans << '\n';
    return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...