Submission #1339620

#TimeUsernameProblemLanguageResultExecution timeMemory
1339620top1svtinStove (JOI18_stove)C++17
100 / 100
14 ms2000 KiB
#include <bits/stdc++.h>

using namespace std;

#define kien long long
#define int long long
#define pb push_back
#define FOR(i, a, b) for (int i = a;i <= b; i++)
#define FORD(i, a, b) for (int i = a;i >= b; i--)
#define pii pair<int, int>
#define dembit(a) __builtin_popcountll(a)
#define task "kien"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define debug(x) cout << x << " "
#define down cout << "\n"
const kien MOD = 1e9 + 7;
const int NTEST = 100;
const int Million = 1e6;
const int MXN = 1e5 + 5;
const int INF = 1e15;

mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count());
kien rand(kien l, kien r) {
    assert(l <= r);
    return uniform_int_distribution<kien>(l, r)(rd);
}

kien n, k, m, u, v, h, a[MXN], b[MXN];
kien maxx, minn, vtr, x, l, r, ans;

void solve() {
    cin >> n >> k;

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

    sort(a + 1, a + n + 1);

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

    FOR (i, 1, n - 1) {
        b[i] = a[i + 1] - a[i] - 1;
    }

    sort (b + 1, b + n);

    ans = n;

    FOR(i, 1, n - k) {
        ans += b[i];
    }

    cout << ans;
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    if (fopen(task".inp", "r")) {
        fin(task); //fou(task);
    }

    int t = 1;  //cin >> t;
    while(t--) solve();

}

Compilation message (stderr)

stove.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main() {
      | ^~~~
stove.cpp: In function 'int main()':
stove.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
stove.cpp:64:9: note: in expansion of macro 'fin'
   64 |         fin(task); //fou(task);
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...