#include "bits/stdc++.h"
using namespace std;
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"
template<typename T> bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T> bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
const int MAX = 2e5 + 5;
int X, N, M, W, T, S[MAX], C[MAX], D[MAX];
ll sumC[MAX], dp[MAX];
struct refilling_point{
int S;
bool operator < (const refilling_point& other){
return S < other.S;
}
} refilling_points[MAX];
struct passenger{
int D, C;
bool operator < (const passenger& other){
return D < other.D;
}
} passengers[MAX];
const ll inf = 4e18;
struct line{
ll a, b;
line(ll a = 0, ll b = 0) : a(a), b(b) {}
ll eval(ll x){ return a * x + b; }
};
struct LichaoTree{
int n;
vector<line> st;
LichaoTree(int n) : st(n << 2, line(0, inf)) {}
void update(int id, int l, int r, line d){
if(l == r){
if(d.eval(l) < st[id].eval(l)){
st[id] = d;
}
} else{
int mid = l + r >> 1;
if(st[id].a < d.a) swap(st[id], d);
if(st[id].eval(mid) > d.eval(mid)){
swap(st[id], d);
update(id << 1, l, mid, d);
} else{
update(id << 1 | 1, mid + 1, r, d);
}
}
}
ll query(int id, int l, int r, int x){
if(l == r) return st[id].eval(x);
int mid = l + r >> 1;
if(x <= mid) return min(st[id].eval(x), query(id << 1, l, mid, x));
else return min(st[id].eval(x), query(id << 1 | 1, mid + 1, r, x));
}
void insertLine(line d){
update(1, 1, n, d);
}
ll query(int x){
return query(1, 1, n, x);
}
};
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// #define filename "task"
// if(fopen(filename".inp", "r")){
// freopen(filename".inp", "r", stdin);
// freopen(filename".out", "w", stdout);
// }
cin >> X >> N >> M >> W >> T;
for(int i = 1; i <= N; ++i){
cin >> refilling_points[i].S;
}
for(int i = 1; i <= M; ++i){
cin >> passengers[i].D >> passengers[i].C;
}
sort(refilling_points + 1, refilling_points + 1 + N);
sort(passengers + 1, passengers + 1 + M);
ll driver_cost = 1LL * ((X / T) + 1) * W;
for(int i = 1; i <= M; ++i){
sumC[i] = sumC[i - 1] + passengers[i].C;
}
LichaoTree trick(M);
refilling_points[++N].S = X;
for(int i = M, j = N; i >= 1; --i){
dp[i] = dp[i + 1] + 1ll * W * ((X - passengers[i].D) / T + 1);
while(j > 0 && (refilling_points[j].S % T) > passengers[i].D){
line d(-1LL * W * (refilling_points[j].S / T), 1LL * W * (refilling_points[j].S / T) * (i + 1) + sumC[i] + dp[i + 1]);
trick.insertLine(d);
--j;
}
minimize(dp[i], trick.query(i) - sumC[i - 1]);
}
cout << dp[1] + driver_cost << '\n';
return 0;
}
Compilation message
coach.cpp: In member function 'void LichaoTree::update(int, int, int, line)':
coach.cpp:66:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
66 | int mid = l + r >> 1;
| ~~^~~
coach.cpp: In member function 'll LichaoTree::query(int, int, int, int)':
coach.cpp:79:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
79 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 8 |
2 |
Halted |
0 ms |
0 KB |
- |