Submission #288485

#TimeUsernameProblemLanguageResultExecution timeMemory
288485BlagojceDischarging (NOI20_discharging)C++11
0 / 100
1091 ms8636 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) #include <time.h> #include <cmath> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int i_inf = 1e9; const ll inf = 1e18; const ll mod = 1000000007; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t timer = clock(); const int mxn = 2e5+5; const ll A = 911382323; const ll B = 972663749; void solve(){ int n; cin >> n; ll a[n]; fr(i, 0, n){ cin >> a[i]; } ll dp[n+1]; dp[n] = 0; for(int i = n-1; i >= 0; i --){ dp[i] = a[i]*(n-i); ll mi = dp[i+1]; fr(j, i+1, n){ if(a[j] >= a[i]) break; mi = min(dp[j+1], mi); } dp[i] += mi; } ll mx = 0; ll ans = inf; fr(i, 0, n){ mx = max(mx, a[i]); ans = min(ans, dp[i+1]+mx*n); } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; while(tc--) solve(); }
#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...