Submission #1241907

#TimeUsernameProblemLanguageResultExecution timeMemory
1241907sunitStove (JOI18_stove)C++20
100 / 100
19 ms2752 KiB
#include<bits/stdc++.h>
#define int long long
#define bl bool
#define db double 
#define fl float 
#define st string 
#define pb push_back
#define pf push_front
#define is insert
#define endl "\n"
#define pba pop_back
#define pfr pop_front
#define ub upper_bound
#define lb lower_bound 
#define fi first 
#define se second 
#define FOR(i, l, r, st) for(int i = l; i <= r; i += st)
#define FOS(i, l, r, sl) for(int i = l; i >= r; i -= sl)
#define mii map<int, int>
#define us unordered_set 
#define pii pair<int, int>
#define vt vector
using namespace std;

const int maxn = 1e6 + 5;

const int mod = 1e9 + 7;

void suncuti() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

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

int n, k, a[maxn];

vt<int>kt;

main() {
    suncuti();

    cin >> n >> k;

    FOR(i, 1, n, 1) {
        cin >> a[i];
    }

    FOR(i, 2, n, 1) {
        kt.pb(a[i] - a[i - 1]);
    }

    sort(kt.begin(), kt.end());

    if(n == k) {
        cout << n;
        return 0;
    }

    queue<int>q;

    FOR(i, 0, kt.size() - 1, 1) {
        if(q.size() < n - k) {
            q.push(kt[i]);
        } else break;
    }

    int res = 0;

    while(q.size()) {
        res += q.front();
        q.pop();
    }

    cout << res + k;
}

Compilation message (stderr)

stove.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main() {
      | ^~~~
stove.cpp: In function 'void fre()':
stove.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen("name.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("name.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...