제출 #821901

#제출 시각아이디문제언어결과실행 시간메모리
821901LiudasSalesman (IOI09_salesman)C++17
15 / 100
39 ms6100 KiB
#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 timeMemoryGrader output
Fetching results...