# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397418 | Nicholas_Patrick | Building Bridges (CEOI17_building) | C++17 | 3058 ms | 4392 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.
#include <cstdio>
#include <queue>
using namespace std;
struct line{
long long m, c;
line(long long m, long long c):m(m), c(c){}
long long eval(long long x){
return m*x+c;
}
};
int main(){
int n;
scanf("%d", &n);
vector<int> h(n), w(n);
for(int& i: h)
scanf("%d", &i);
long long sumw=0;
for(int& i: w){
scanf("%d", &i);
sumw+=i;
i=-i;
}
vector<line> ch;
ch.emplace_back(-2*h[0], (long long)h[0]*h[0]+w[0]);
for(int i=1; i+1<n; i++){
long long cost=1e18;
for(auto& j: ch)
cost=min(cost, j.eval(h[i]));
cost+=(long long)h[i]*h[i]+w[i];
ch.emplace_back(-2*h[i], (long long)h[i]*h[i]+cost);
}
long long ans=1e18;
for(auto& j: ch)
ans=min(ans, j.eval(h[n-1]));
ans+=(long long)h[n-1]*h[n-1]+w[n-1]+sumw;
printf("%lld\n", ans);
}
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... |