Submission #1033711

# Submission time Handle Problem Language Result Execution time Memory
1033711 2024-07-25T04:19:29 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
22 ms 1200 KB
#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

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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 13 ms 1112 KB Output is correct
17 Correct 13 ms 1200 KB Output is correct
18 Correct 16 ms 1116 KB Output is correct
19 Correct 13 ms 1200 KB Output is correct
20 Correct 22 ms 1116 KB Output is correct
21 Correct 13 ms 1192 KB Output is correct
22 Correct 22 ms 1116 KB Output is correct
23 Correct 13 ms 1200 KB Output is correct
24 Correct 13 ms 1116 KB Output is correct