Submission #1241803

#TimeUsernameProblemLanguageResultExecution timeMemory
1241803trinm01Stove (JOI18_stove)C++20
100 / 100
12 ms1864 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>

const ll mod = 1e7 + 1203;
const ll MAXN = 3e5 + 5;
const ll oo = 1e18;
const ll base = 320;

int n, k, a[MAXN], b[MAXN];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    if (fopen("board.INP", "r"))
    {
        freopen("board.INP", "r", stdin);
        freopen("board.OUT", "w", stdout);
    }

    cin >> n >> k;
    FOR(i, 1, n){
        cin >> a[i];
        if(i!=1){
            b[i]=a[i]-a[i-1]-1;
        }
    }
    sort(b+1, b+1+n);
    reverse(b+1, b+1+n);
    int ans=a[n]+1-a[1];
    FOR(i, 1, k-1){
        ans-=b[i];
    }
    cout << ans;

    return 0;
}

Compilation message (stderr)

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