#pragma warning(suppress : 4996)
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)
#define all(x) x.begin(),x.end()
#define me(x,a) memset(x,a,sizeof(x))
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int N; i64 U, D, S; cin >> N >> U >> D >> S;
//dp[i] = max profit after considering all events until i
//dp[i] = dp[j] + (pos[i] - pos[j]) * U if pos[i] < pos[j]
//dp[i] = dp[j] + (pos[j] - pos[i]) * D if pos[i] > pos[j]
vector<i64> dp(N + 2, -1E18);
vector<i64> date(N + 2), pos(N + 2), profit(N + 2);
L(i, 1, N) cin >> date[i] >> pos[i] >> profit[i];
pos[0] = S; date[0] = -1E18; pos[N + 1] = S; date[N + 1] = 1E18;
vector<int> ord(N + 2); iota(all(ord), 0);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return date[i] < date[j];
});
dp[0] = 0;
L(i, 1, N + 1) {
L(j, 0, i - 1) {
if (pos[ord[i]] <= pos[ord[j]]) dp[i] = max(dp[i], dp[j] + profit[ord[i]] - (pos[ord[j]] - pos[ord[i]]) * D);
else dp[i] = max(dp[i], dp[j] + profit[ord[i]] - (pos[ord[i]] - pos[ord[j]]) * U);
}
}
cout << dp[N + 1] << '\n';
}
Compilation message
salesman.cpp:1: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
1 | #pragma warning(suppress : 4996)
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
348 KB |
Output is correct |
5 |
Correct |
47 ms |
604 KB |
Output is correct |
6 |
Correct |
754 ms |
1532 KB |
Output is correct |
7 |
Execution timed out |
3040 ms |
2908 KB |
Time limit exceeded |
8 |
Execution timed out |
3017 ms |
4944 KB |
Time limit exceeded |
9 |
Execution timed out |
3048 ms |
7252 KB |
Time limit exceeded |
10 |
Execution timed out |
3042 ms |
13652 KB |
Time limit exceeded |
11 |
Execution timed out |
3048 ms |
13936 KB |
Time limit exceeded |
12 |
Execution timed out |
3045 ms |
17592 KB |
Time limit exceeded |
13 |
Execution timed out |
3052 ms |
17748 KB |
Time limit exceeded |
14 |
Execution timed out |
3062 ms |
22616 KB |
Time limit exceeded |
15 |
Execution timed out |
3079 ms |
22352 KB |
Time limit exceeded |
16 |
Execution timed out |
3042 ms |
22248 KB |
Time limit exceeded |
17 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
19 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
11 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
12 ms |
348 KB |
Output isn't correct |
22 |
Incorrect |
43 ms |
856 KB |
Output isn't correct |
23 |
Incorrect |
47 ms |
600 KB |
Output isn't correct |
24 |
Incorrect |
48 ms |
600 KB |
Output isn't correct |
25 |
Execution timed out |
3061 ms |
4956 KB |
Time limit exceeded |
26 |
Execution timed out |
3023 ms |
8784 KB |
Time limit exceeded |
27 |
Execution timed out |
3035 ms |
15188 KB |
Time limit exceeded |
28 |
Execution timed out |
3046 ms |
15444 KB |
Time limit exceeded |
29 |
Execution timed out |
3043 ms |
21720 KB |
Time limit exceeded |
30 |
Execution timed out |
3027 ms |
21992 KB |
Time limit exceeded |