This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//subtask 1
#include <bits/stdc++.h>
#include "squad.h"
using namespace std;
typedef long long ll;
int n;
vector<ll> a, d, p;
void Init(std::vector<int> A, std::vector<int> D, std::vector<int> P){
n = (int)A.size();
for (int i = 0; i < n; i++) {
a.push_back(A[i]);
d.push_back(D[i]);
p.push_back(P[i]);
}
}
ll BestSquad(int X, int Y){
vector<ll> am(n), dm(n);
vector<ll> pdm(n), sdm(n);
for (int i = 0; i < n; i++) {
am[i] = X * a[i] + Y * p[i];
dm[i] = X * d[i] + Y * p[i];
}
pdm[0] = dm[0];
for (int i = 1; i < n; i++)
pdm[i] = max(pdm[i - 1], dm[i]);
sdm[n - 1] = dm[n - 1];
for (int i = n - 2; i >= 0; i--)
sdm[i] = max(sdm[i + 1], dm[i]);
ll ret = 0;
for (int i = 0; i < n; i++)
ret = max(ret, am[i] + max(i ? pdm[i - 1] : 0, i + 1 < n ? sdm[i + 1] : 0));
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |