# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
282630 | DystoriaX | Long Distance Coach (JOI17_coach) | C++14 | 2061 ms | 14292 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 <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
long long x, t;
int n, m, w;
long long s[200010];
pair<long long, int> v[200010];
long long pos[200010], spos[200010];
long long dp[200010], ans;
long long Get(long long x){
return x - (x % t);
}
int main(){
scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
for(int i = 1; i <= n; i++) scanf("%lld", &s[i]);
for(int i = 1; i <= m; i++) scanf("%lld%d", &v[i].fi, &v[i].se), pos[i] = v[i].fi;
sort(v + 1, v + 1 + m);
sort(pos + 1, pos + 1 + m);
memset(spos, -1, sizeof(spos));
s[n + 1] = x;
for(int i = 1; i <= n + 1; i++){
int id = upper_bound(pos + 1, pos + 1 + m, s[i] % t) - pos;
--id;
if(spos[id] == -1 || spos[id] > s[i]) spos[id] = s[i];
}
for(int i = 0; i <= m; i++)
ans += (x - v[i].fi) / t + 1;
ans *= w;
for(int i = 1; i <= m; i++){
dp[i] = dp[i - 1];
if(spos[i] == -1) continue;
long long cost = 0;
for(int k = i - 1; k >= 0; k--){
cost += -((x - (Get(spos[i]) + v[k + 1].fi)) / t + 1) * w + v[k + 1].se;
dp[i] = min(dp[i], dp[k] + cost);
}
}
printf("%lld\n", ans + dp[m]);
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... |