Submission #1099478

#TimeUsernameProblemLanguageResultExecution timeMemory
1099478NoMercyDischarging (NOI20_discharging)C++17
20 / 100
73 ms25724 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e6 + 55; ll dp[MAXN], T[MAXN]; int f (array<ll, 2> line, int x) { return line[0] * x + line[1]; } long double intersect (array<ll, 2> line1, array<ll, 2> line2) { return (line2[1] - line1[1]) / (line1[0] - line2[0]); } struct Hull { deque<array<ll, 2>> dq; int query (int x) { while ((int)dq.size() > 1 && f(dq[0], x) > f(dq[1], x)) dq.pop_front(); return f(dq[0], x); } void insert (array<ll, 2> line) { while (dq.size() > 1 && intersect(line, dq.back()) <= intersect(line, dq[dq.size() - 2])) dq.pop_back(); dq.push_back(line); } }; int32_t main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; cin >> N; for (int i = 1;i <= N;i ++) { cin >> T[i]; } Hull hl; ll mx = 1; int ind = 1; for (int i = 1;i <= N;i ++) { if (T[i] >= T[mx]) { mx = i; } while (ind <= mx){ hl.insert({-1LL * ind, dp[ind - 1]}); ind ++; } if (i > 1) { dp[i] = min(T[mx] * N, hl.query(T[mx]) + T[mx] * (N + 1)); } else { dp[i] = T[1] * N; } } cout << dp[N] << "\n"; }
#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...