Submission #439669

#TimeUsernameProblemLanguageResultExecution timeMemory
439669MohamedAhmed04Discharging (NOI20_discharging)C++14
0 / 100
130 ms21628 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 1e6 + 10 ; int arr[MAX] ; int n ; long long dp[MAX] ; int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n ; for(int i = 1 ; i <= n ; ++i) cin>>arr[i] ; stack<int>s ; for(int i = 1 ; i <= n ; ++i) { while(s.size() && arr[i] >= s.top()) s.pop() ; if(s.size()) dp[i] = dp[s.top()] + 1ll * arr[i] * (i - s.top()) ; else dp[i] = 1ll * arr[i] * i ; s.push(i) ; } long long ans = 4e18 ; while(s.size()) { ans = min(ans , dp[s.top()] + 1ll * arr[s.top()] * (n - s.top())) ; s.pop() ; } return cout<<ans<<"\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...