# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
432956 | jhnah917 | Salesman (IOI09_salesman) | C++14 | 487 ms | 24928 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int SZ = 1 << 19;
struct SegmentTree{
int T[SZ << 1];
SegmentTree(){ memset(T, 0xc0, sizeof T); }
void update(int x, int v){
x |= SZ; T[x] = max(T[x], v);
while(x >>= 1) T[x] = max(T[x], v);
}
int query(int l, int r){
l |= SZ; r |= SZ; int ret = T[0];
while(l <= r){
if(l & 1) ret = max(ret, T[l++]);
if(~r & 1) ret = max(ret, T[r--]);
l >>= 1; r >>= 1;
}
return ret;
}
};
struct Info{
int t, l, m; // time, location, money
bool operator < (const Info &info) const {
return t < info.t;
}
};
int N, U, D, S, DP[505050];
Info A[505050];
SegmentTree T_D, T_U;
void Update(int idx){
T_D.update(A[idx].l, DP[idx] + D * A[idx].l);
T_U.update(A[idx].l, DP[idx] - U * A[idx].l);
}
int Query(int idx){
int dw = T_D.query(0, A[idx].l) - D * A[idx].l + A[idx].m;
int up = T_U.query(A[idx].l, 505050) + U * A[idx].l + A[idx].m;
return max(dw, up);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> N >> U >> D >> S;
for(int i=1; i<=N; i++) cin >> A[i].t >> A[i].l >> A[i].m;
A[0] = {0, S, 0}; // start
A[++N] = {505050, S, 0}; // end
sort(A+1, A+N+1);
memset(DP, 0xc0, sizeof DP);
DP[0] = 0; Update(0);
for(int i=1; i<=N; i++){
DP[i] = Query(i);
Update(i);
}
cout << DP[N];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |