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 <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];
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);
}
}
for (int i = 0; i < m; ++i) {
dp[i + 1] = dp[i] + cost[i];
for (int j = 0; j <= i; ++j) {
cost[j] = min(cost[j], mn[i]);
}
ll sum = 0;
if (mn[i] < INF) {
for (int j = i; j >= 0; --j) {
sum += cost[j] + c[j];
dp[i + 1] = min(dp[i + 1], dp[j] + sum);
}
}
}
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... |