# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
492704 | zhougz | Discharging (NOI20_discharging) | C++17 | 138 ms | 13928 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: chowgz
* created: 14/03/2021 11:20:55
**/
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = (int)1e6;
struct Line {
int m;
long long c;
long long operator()(int x) {
return (long long)m * x + c;
}
double operator^(const Line &rhs) {
return ((double)c - rhs.c) / ((double)rhs.m - m);
}
};
struct ConvexHull {
Line lines[MAXN + 1];
int l = 0, r = 0;
void operator+=(Line line) {
while (r - l >= 2 && (line ^ lines[r - 1]) <= (lines[r - 1] ^ lines[r - 2])) {
r--;
}
lines[r] = line;
r++;
}
long long operator()(int x) {
while (r - l >= 2 && lines[l](x) >= lines[l + 1](x)) {
l++;
}
return lines[l](x);
}
} hull;
// For more comments, check original cpp file!
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long long dp;
int maxx = 0;
hull += Line{0, 0};
for (int i = 1; i <= n; i++) {
if (arr[i - 1] > maxx) {
maxx = arr[i - 1];
dp = n * (long long)maxx + hull(maxx);
}
hull += Line{-i, dp};
}
cout << dp << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |