제출 #1033711

#제출 시각아이디문제언어결과실행 시간메모리
1033711vjudge1Stove (JOI18_stove)C++17
100 / 100
22 ms1200 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);
}

컴파일 시 표준 에러 (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...