#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 205050
#define MAXS 20
#define INF (ll)1e18
#define bb ' '
#define ln '\n'
#define Ln '\n'
#ifdef _MSC_VER
# include <intrin.h>
# define __builtin_popcount __popcnt
#endif
#define MOD 1000000007
struct Line {
ll a, b;
Line(ll a = 0, ll b = INF) :a(a), b(b) {}
ll operator[](ll x) { return a * x + b; }
};
struct segtree {
struct Node {
int l, r;
ll low, high;
Line f;
};
vector<Node> tree;
segtree(ll l, ll r) { tree.push_back({ -1, -1, l, r, Line() }); }
void upd(int loc, Line f) {
ll l, r;
l = tree[loc].low;
r = tree[loc].high;
auto pv = tree[loc].f;
if (f[l] > pv[l]) swap(f, pv);
if (f[r] <= pv[r]) {
tree[loc].f = f;
return;
}
ll m = (l + r) >> 1;
if (f[m] > pv[m]) {
tree[loc].f = pv;
if (!~tree[loc].l) {
tree[loc].l = tree.size();
tree.push_back({ -1, -1, l, m, Line() });
}
upd(tree[loc].l, f);
}
else {
tree[loc].f = f;
if (!~tree[loc].r) {
tree[loc].r = tree.size();
tree.push_back({ -1, -1, m + 1, r, Line() });
}
upd(tree[loc].r, f);
}
}
ll query(int loc, ll x) {
if (!~loc) return INF;
ll m = (tree[loc].low + tree[loc].high) >> 1;
if (x <= m) return min(query(tree[loc].l, x), tree[loc].f[x]);
else return min(query(tree[loc].r, x), tree[loc].f[x]);
}
};
vector<ll> dps[MAX];
int C[MAX];
ll dp[MAX];
ll S[MAX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M;
ll W, X, T;
cin >> X >> N >> M >> W >> T;
int i;
ll a, b;
vector<ll> s = { X };
for (i = 1; i <= N; i++) cin >> a, s.push_back(a);
vector<pii> in;
vector<int> lst = { 0 };
for (i = 1; i <= M; i++) cin >> a >> b, in.emplace_back(a, b), lst.push_back(a);
sort(in.begin(), in.end());
for (i = 1; i <= M; i++) C[i] = in[i - 1].second;
sort(lst.begin(), lst.end());
for (auto x : s) dps[lower_bound(lst.begin(), lst.end(), x % T) - lst.begin() - 1].push_back(x / T);
for (i = 1; i <= M; i++) S[i] = S[i - 1] + C[i];
segtree seg(1, N);
for (i = M; i >= 1; i--) {
for (auto v : dps[i]) seg.upd(0, Line(-v * W, v * W * (ll)(i + 1) + dp[i + 1] + S[i]));
dp[i] = min(seg.query(0, i) - S[i - 1], dp[i + 1] + W * ((X - lst[i]) / T + 1));
}
cout << dp[1] + W * (X / T + 1) << ln;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5148 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5128 KB |
Output is correct |
6 |
Correct |
3 ms |
5148 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
2 ms |
5152 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5148 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5148 KB |
Output is correct |
18 |
Correct |
3 ms |
5148 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5148 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5128 KB |
Output is correct |
6 |
Correct |
3 ms |
5148 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
2 ms |
5152 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5148 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5148 KB |
Output is correct |
18 |
Correct |
3 ms |
5148 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5148 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5128 KB |
Output is correct |
6 |
Correct |
3 ms |
5148 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
2 ms |
5152 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5148 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5148 KB |
Output is correct |
18 |
Correct |
3 ms |
5148 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5148 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Correct |
3 ms |
5128 KB |
Output is correct |
6 |
Correct |
3 ms |
5148 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
2 ms |
5152 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5148 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5148 KB |
Output is correct |
18 |
Correct |
3 ms |
5148 KB |
Output is correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |