Submission #837161

#TimeUsernameProblemLanguageResultExecution timeMemory
83716112345678Discharging (NOI20_discharging)C++17
9 / 100
1036 ms8672 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=1e6+5; ll n, t[nx], dp[nx][2]; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>t[i]; for (int i=1; i<=n; i++) { ll mx=t[i]; dp[i][0]=dp[i][1]=1e18; for (int j=i-1; j>=0; j--) { if (dp[j][0]+(dp[j][1]+mx)*(i-j)<dp[i][0]) { dp[i][0]=dp[j][0]+(dp[j][1]+mx)*(i-j); dp[i][1]=dp[j][1]+mx; } else if (dp[j][0]+(dp[j][1]+mx)*(i-j)==dp[i][0]) dp[i][1]=min(dp[i][1], dp[j][1]+mx); mx=max(mx, t[j]); } //cout<<i<<' '<<dp[i][0]<<' '<<dp[i][1]<<'\n'; } cout<<dp[n][0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...