#include <bits/stdc++.h>
using namespace std;
struct line {
__int128 k, n;
line(__int128 _k = 0, __int128 _n = 0) : k(_k), n(_n) {}
__int128 val(__int128 x) {
return k * x + n;
}
};
const int MAX = 1e7;
int root, ls[MAX], rs[MAX], tsz;
line st[MAX];
void Modify(int& x, long long l, long long r, line ln) {
if (!x) {
x = ++tsz;
st[x] = line(0, (__int128) 2e18);
}
long long mid = l + r >> 1;
if (st[x].val(mid) > ln.val(mid)) {
swap(st[x], ln);
}
if (l == r) {
return;
}
if (st[x].val(l) > ln.val(l)) {
Modify(ls[x], l, mid, ln);
} else {
Modify(rs[x], mid + 1, r, ln);
}
}
__int128 Query(int x, long long l, long long r, long long i) {
if (!x) {
return (__int128) 1e18;
}
if (l == r) {
return st[x].val(i);
}
long long mid = l + r >> 1;
if (i <= mid) {
return min(st[x].val(i), Query(ls[x], l, mid, i));
} else {
return min(st[x].val(i), Query(rs[x], mid + 1, r, i));
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long x, t;
int n, m, w;
cin >> x >> n >> m >> w >> t;
vector<long long> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
s.push_back(x);
n += 1;
m += 1;
vector<long long> d(m);
vector<int> c(m);
for (int i = 1; i < m; i++) {
cin >> d[i] >> c[i];
}
d[0] = 0;
c[0] = 0;
vector<int> order(m);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
return d[i] < d[j];
});
{
vector<long long> new_d(m);
vector<int> new_c(m);
for (int i = 0; i < m; i++) {
new_d[i] = d[order[i]];
new_c[i] = c[order[i]];
}
d = new_d;
c = new_c;
}
const long long inf = (long long) 1e18;
vector<long long> fir(m, inf);
for (int i = 0; i < n; i++) {
int low = 0, high = m - 1, idx = -1;
while (low <= high) {
int mid = low + high >> 1;
if (d[mid] < (s[i] % t)) {
idx = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
if (idx != -1) {
fir[idx] = min(fir[idx], s[i] / t);
}
}
vector<__int128> dp(m);
dp[0] = (__int128) (x / t + 1) * (__int128) w;
long long sum_c = 0;
for (int i = 1; i < m; i++) {
dp[i] = dp[i - 1] + (__int128) ((x - d[i]) / t + 1) * (__int128) w;
Modify(root, 0, (long long) 1e12, line(-((i - 1) * 1LL * w), dp[i - 1] - sum_c));
sum_c += c[i];
if (fir[i] != inf) {
dp[i] = min(dp[i], Query(root, 0, (long long) 1e12, fir[i]) + (__int128) fir[i] * (__int128) i * (__int128)w + sum_c);
}
}
cout << (long long) dp[m - 1] << '\n';
return 0;
}
Compilation message
coach.cpp: In function 'void Modify(int&, long long int, long long int, line)':
coach.cpp:23:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | long long mid = l + r >> 1;
| ~~^~~
coach.cpp: In function '__int128 Query(int, long long int, long long int, long long int)':
coach.cpp:44:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
44 | long long mid = l + r >> 1;
| ~~^~~
coach.cpp: In function 'int main()':
coach.cpp:92:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
92 | int mid = low + high >> 1;
| ~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |