Submission #127376

#TimeUsernameProblemLanguageResultExecution timeMemory
127376FutymyCloneStove (JOI18_stove)C++14
100 / 100
35 ms2316 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n, k, a[N], ans = 0;

int main(){
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    ans = a[n] + 1 - a[1];
    priority_queue <int> pq;

    for (int i = 2; i <= n; i++) pq.push(a[i] - (a[i - 1] + 1));
    while (k > 1) {
        k--;
        ans -= pq.top();
        pq.pop();
    }

    printf("%d", ans);
    return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:11:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...