Submission #439671

#TimeUsernameProblemLanguageResultExecution timeMemory
439671MohamedAhmed04Discharging (NOI20_discharging)C++14
11 / 100
173 ms21828 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 = n ; i >= 1 ; --i) { while(s.size() && arr[i] >= s.top()) s.pop() ; if(s.size()) dp[i] = dp[s.top()] ; dp[i] += 1ll * arr[i] * (n-i+1ll) ; s.push(i) ; } long long ans = 4e18 ; while(s.size()) { ans = min(ans , dp[s.top()] + 1ll * arr[s.top()] * (s.top() - 1ll)) ; 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...