Submission #136936

#TimeUsernameProblemLanguageResultExecution timeMemory
136936arnold518오렌지 출하 (JOI16_ho_t1)C++14
100 / 100
68 ms888 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e4;

int N, M;
ll K, A[MAXN+10], dp[MAXN+10];

int main()
{
    int i, j;
    scanf("%d%d%lld", &N, &M, &K);
    for(i=1; i<=N; i++) scanf("%lld", &A[i]);

    for(i=1; i<=N; i++)
    {
        ll a=A[i], b=A[i], s=0;
        dp[i]=numeric_limits<ll>::max();
        for(j=i; j>=1 && i-j+1<=M; j--)
        {
            a=max(A[j], a);
            b=min(A[j], b);
            s++;
            dp[i]=min(dp[i], dp[j-1]+K+s*(a-b));
        }
    }
    printf("%lld", dp[N]);
}

Compilation message (stderr)

2016_ho_t1.cpp: In function 'int main()':
2016_ho_t1.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%lld", &N, &M, &K);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t1.cpp:17:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%lld", &A[i]);
                         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...