Submission #164735

#TimeUsernameProblemLanguageResultExecution timeMemory
164735quocnguyen1012Stove (JOI18_stove)C++14
100 / 100
27 ms2296 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    int N, K;
    cin >> N >> K;
    --K;
    vector<int> a(N), b;
    for (int i=0; i<N; ++i){
        cin >> a[i];
        if (i){
            b.pb(a[i]-a[i-1]-1);
        }
    }
    sort(b.rbegin(), b.rend());
    int res = a[N-1] - a[0] + 1;
    for (int i=0; i<K; ++i){
        res -= b[i];
    }
    cout << res << '\n';
}

Compilation message (stderr)

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