Submission #335773

#TimeUsernameProblemLanguageResultExecution timeMemory
335773ChrisT오렌지 출하 (JOI16_ho_t1)C++17
100 / 100
57 ms896 KiB
#include <bits/stdc++.h> using namespace std; const int MN = 2e4 + 5; int a[MN];long long dp[MN]; int main() { int n,m,k; scanf ("%d %d %d",&n,&m,&k); for (int i = 1; i <= n; i++) { scanf ("%d",&a[i]); int mx = a[i], mn = a[i], ed = max(1,i-m+1); dp[i] = 2e18; for (int j = i; j >= ed; j--) { mx = max(mx,a[j]); mn = min(mn,a[j]); dp[i] = min(dp[i],dp[j-1] + k + (long long)(i-j+1) * (mx - mn)); } } printf ("%lld\n",dp[n]); return 0; }

Compilation message (stderr)

2016_ho_t1.cpp: In function 'int main()':
2016_ho_t1.cpp:7:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |  scanf ("%d %d %d",&n,&m,&k);
      |  ~~~~~~^~~~~~~~~~~~~~~~~~~~~
2016_ho_t1.cpp:9:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |   scanf ("%d",&a[i]); int mx = a[i], mn = a[i], ed = max(1,i-m+1); dp[i] = 2e18;
      |   ~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...