Submission #1033523

#TimeUsernameProblemLanguageResultExecution timeMemory
1033523sp69tStove (JOI18_stove)C++14
100 / 100
14 ms2140 KiB
#include <stdio.h>
#include <algorithm>
int a[100100], s[100100];
int main() {
    int n, k, res; scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    res = a[n] - a[1] + 1;
    for (int i = 1; i < n; ++i) s[i] = a[i + 1] - a[i] - 1;
    std::sort(s + 1, s + n);

    // for (int i = 1; i < n; i++) printf("%d ", s[i]);
    // printf("\n");

    for (int i = 0, j = n - 1; i < k - 1 && j; ++i, --j) res -= s[j];
    printf("%d", res);
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |     int n, k, res; scanf("%d %d", &n, &k);
      |                    ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:6:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     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...