# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
821901 | Liudas | Salesman (IOI09_salesman) | C++17 | 39 ms | 6100 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>
using namespace std;
int N, U, D, S;
struct node{
int pos;
int pro;
int day;
bool operator<(node a){
if(day == a.day){
return abs(pos-S) < abs(a.pos-S);
}
return day < a.day;
}
};
int main()
{
cin >> N >> U >> D >> S;
vector<node> arr(N+1, {0, 0, 0});
arr[0].day = -1;
arr[0].pos = S;
if(N > 5000){
return 0;
}
for(int i = 1; i <= N; i ++){
cin >> arr[i].day >> arr[i].pos >> arr[i].pro;
}
sort(arr.begin(), arr.end());
vector<int> DP(N+1);
for(int i = 1; i <= N; i ++){
int mx = -1e9;
for(int j = 0; j < i; j ++){
mx = max(mx, -(arr[j].pos - arr[i].pos > 0 ? (arr[j].pos - arr[i].pos) * D : -(arr[j].pos - arr[i].pos) * U) + DP[j]);
}
DP[i] += mx + arr[i].pro;
}
int ans = 0;
for(int i = 0; i <= N; i ++){
ans = max(ans, DP[i] - (S - arr[i].pos > 0 ? (S - arr[i].pos) * U : -(S - arr[i].pos) * D));
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |