이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
const ll INF = 2e18;
int n, m;
ll X, T, W;
ll s[N];
ll d[N], c[N];
ll cost[N];
ll mn[N];
ll dp[N];
ll prefc[N];
struct seg {
int l, r;
ll x, sumcost, mnval;
};
ll get(int l, int r, ll x) {
ll ret = INF;
for (int i = l; i < r; ++i) {
ret = min(ret, dp[i] - prefc[i] - x * i);
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> X >> n >> m >> W >> T;
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
sort(s, s + n);
s[n++] = X;
{
vector<pair<ll, ll>> kek(m);
for (int i = 0; i < m; ++i) {
cin >> kek[i].first >> kek[i].second;
}
sort(kek.begin(), kek.end());
for (int i = 0; i < m; ++i) {
d[i] = kek[i].first;
c[i] = kek[i].second;
}
}
for (int i = 0; i < m; ++i) {
cost[i] = ((X - d[i]) / T + 1) * W;
}
for (int i = 0; i < m; ++i) {
mn[i] = INF;
}
for (int i = 0; i < n; ++i) {
int ind = lower_bound(d, d + m, s[i] % T) - d - 1;
if (ind != -1) {
mn[ind] = min(mn[ind], s[i] / T * W);
}
}
prefc[0] = 0;
for (int i = 0; i < m; ++i) {
prefc[i + 1] = prefc[i] + c[i];
}
vector<seg> st;
st.push_back({0, 0, -1, 0, INF});
for (int i = 0; i < m; ++i) {
dp[i + 1] = dp[i] + cost[i];
if (mn[i] != INF) {
while (st.back().x >= mn[i]) {
st.pop_back();
}
seg kek;
kek.l = st.back().r;
kek.r = i + 1;
kek.x = mn[i];
kek.sumcost = st.back().sumcost + kek.x * (kek.r - kek.l);
ll prefcost = st.back().sumcost;
kek.mnval = min(st.back().mnval, get(kek.l, kek.r, kek.x) - prefcost + kek.x * kek.l);
st.push_back(kek);
if (st.back().mnval != INF) {
dp[i + 1] = min(dp[i + 1], st.back().mnval + prefc[i + 1] + st.back().sumcost);
}
}
}
cout << dp[m] + (X / T + 1) * W << "\n";
return 0;
}
# | 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... |