제출 #348301

#제출 시각아이디문제언어결과실행 시간메모리
348301HalogenStove (JOI18_stove)C++14
50 / 100
1094 ms1644 KiB
#include <bits/stdc++.h>

using namespace std;

main() {
    int N, K; scanf("%d %d", &N, &K);
    int lst[N + 5]; lst[0] = 0;
    for (int i = 1; i <= N; i++) scanf("%d", &lst[i]);
    int dp[K + 5]; memset(dp, 63, sizeof(dp));
    dp[K - 1] = 1;
    for (int i = 2; i <= N; i++) {
        for (int j = 0; j < K; j++) {
            dp[j] = min(dp[j] + lst[i] - lst[i - 1], dp[j + 1] + 1);
            // printf("%d ", dp[j]);
        }
        // printf("\n");
    }

    int ans = dp[K - 1];
    for (int i = K - 2; i >= 0; i--) {
        if (dp[i] == dp[K + 3]) break;
        ans = min(ans, dp[i]);
    }
    printf("%d", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

stove.cpp:5:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main() {
      |      ^
stove.cpp: In function 'int main()':
stove.cpp:6:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |     int N, K; scanf("%d %d", &N, &K);
      |               ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:8:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     for (int i = 1; i <= N; i++) scanf("%d", &lst[i]);
      |                                  ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...