Submission #853919

#TimeUsernameProblemLanguageResultExecution timeMemory
853919annabeth9680Discharging (NOI20_discharging)C++17
100 / 100
98 ms29008 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 1e6+11; int arr[MAXN], dp[MAXN], A[MAXN], B[MAXN]; int L,R; int teil(int a, int b){ return a/b-(a % b != 0 && a < 0); } int steigung(int a1, int b1, int a2, int b2){ return teil(b2-b1,a1-a2); } void upd(int i, int x){ while(R-L >= 2 && steigung(A[R-2],B[R-2],i,x) <= steigung(A[R-2],B[R-2],A[R-1],B[R-1])) R--; A[R] = i; B[R] = x; R++; } int query(int x){ while(R-L >= 2 && A[L]*x+B[L] >= A[L+1]*x+B[L+1]) L++; return A[L]*x+B[L]; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; cin >> N; for(int i = 0;i<N;++i) cin >> arr[i]; for(int i = 1;i<N;++i) arr[i] = max(arr[i],arr[i-1]); memset(dp,0x3f,sizeof(dp)); dp[0] = 0; for(int i = 0;i<N;++i){ upd(-i, dp[i]); dp[i+1] = arr[i]*N+query(arr[i]); } cout << dp[N] << "\n"; return 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...