Submission #1228842

#TimeUsernameProblemLanguageResultExecution timeMemory
1228842Tony_TungStove (JOI18_stove)C++17
100 / 100
26 ms2076 KiB
#include <bits/stdc++.h>
#define task ""
#define ll long long
using namespace std;

const int N = 1e5 + 5;
ll a[N];
priority_queue<ll> pq;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }

    int n, k; cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (i >= 2) pq.push(a[i]-a[i-1]-1);
    }
    ll res = a[n]-a[1]+1;
    for (int i = 1; i < k; i++)
    {
        res -= pq.top();
        pq.pop();
    }
    cout << res;

    return 0;
}

Compilation message (stderr)

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