Submission #1241910

#TimeUsernameProblemLanguageResultExecution timeMemory
1241910long123Stove (JOI18_stove)C++20
100 / 100
14 ms2376 KiB
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    if(fopen(".inp", "r"))
    {
        freopen(".inp", "r", stdin);
        freopen(".out", "w", stdout);
    }
    int n, k;
    cin >> n >> k;
    vector<int> t(n);
    for ( int i = 0; i < n; i++ )
    {
        cin >> t[i];
    }
    vector<int> gaps;
    sort(t.begin(), t.end());
    for ( int i = 1; i < n; i++ )
    {
        int gap = t[i] - (t[i - 1] + 1);
        if(gap > 0) 
        {
            gaps.push_back(gap);
        }
    }
    sort(gaps.rbegin(), gaps.rend());
    int tong = t.back() + 1 - t[0];
    int luu = 0;
    for ( int i = 0; i < min(k - 1, (int)gaps.size()); i++ )
    {
        luu += gaps[i];
    }
    cout << tong - luu << "\n";
    return 0;
} 

Compilation message (stderr)

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