#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
//#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define INFST (0x7f7f7f7f)
#define INFLLST (0x7f7f7f7f7f7f7f7fll)
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
typedef complex<ld> base;
const ld EPS = (ld)1e-7;
const ld PI = acos(0) * 2;
bool isZero(const ld& x) { return abs(x) <= EPS; }
int sign(const ld& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return abs(a); }
pll operator + (const pll& a, const pll& b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll& a, const pll& b) { return pll(a.first-b.first, a.second-b.second); }
pll operator * (const pll& a, const ll& b) { return pll(a.first*b, a.second*b); }
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }
int rd(int s, int e) { return rand()%(e-s+1) + s; }
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }
void fg(vector<pii> G[], int a, int b, int c) { G[a].pb({b, c}); G[b].pb({a, c}); }
const int MAXN = 5005;
const int MAXX = 500005;
struct NOD {
NOD(int d = 0, int x = 0, int c = 0) : d(d), x(x), c(c) {}
int d, x, c;
bool operator < (const NOD &t) const {
if(d != t.d) return d < t.d;
return x < t.x;
}
};
int dp[MAXN];
NOD nod[MAXN];
int N, CU, CD, SX;
int main() {
scanf("%d%d%d%d", &N, &CU, &CD, &SX);
for(int i = 1; i <= N; i++) {
int d, x, c;
scanf("%d%d%d", &d, &x, &c);
nod[i] = NOD(d, x, c);
}
nod[N+1] = NOD(0, SX, 0);
nod[N+2] = NOD(MAXX-1, SX, 0);
sort(nod+1, nod+N+3);
N += 2;
for(int i = 2; i <= N; i++) {
int &ret = dp[i]; ret = -INF;
for(int j = 1; j < i; j++) {
if(nod[j].x > nod[i].x) {
upmax(ret, dp[j] - CU * (nod[j].x - nod[i].x) + nod[i].c);
} else {
upmax(ret, dp[j] - CD * (nod[i].x - nod[j].x) + nod[i].c);
}
}
}
cout << dp[N] << endl;
return 0;
}
Compilation message
salesman.cpp: In function 'int main()':
salesman.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &N, &CU, &CD, &SX);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
salesman.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &d, &x, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
9 ms |
448 KB |
Output is correct |
5 |
Correct |
64 ms |
576 KB |
Output is correct |
6 |
Execution timed out |
5 ms |
576 KB |
Time limit exceeded (wall clock) |
7 |
Execution timed out |
5 ms |
576 KB |
Time limit exceeded (wall clock) |
8 |
Execution timed out |
5 ms |
592 KB |
Time limit exceeded (wall clock) |
9 |
Execution timed out |
5 ms |
592 KB |
Time limit exceeded (wall clock) |
10 |
Execution timed out |
6 ms |
612 KB |
Time limit exceeded (wall clock) |
11 |
Execution timed out |
5 ms |
612 KB |
Time limit exceeded (wall clock) |
12 |
Execution timed out |
6 ms |
620 KB |
Time limit exceeded (wall clock) |
13 |
Execution timed out |
4 ms |
620 KB |
Time limit exceeded (wall clock) |
14 |
Execution timed out |
5 ms |
620 KB |
Time limit exceeded (wall clock) |
15 |
Execution timed out |
5 ms |
620 KB |
Time limit exceeded (wall clock) |
16 |
Execution timed out |
5 ms |
620 KB |
Time limit exceeded (wall clock) |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Incorrect |
2 ms |
620 KB |
Output isn't correct |
19 |
Incorrect |
4 ms |
624 KB |
Output isn't correct |
20 |
Incorrect |
13 ms |
700 KB |
Output isn't correct |
21 |
Incorrect |
14 ms |
700 KB |
Output isn't correct |
22 |
Incorrect |
66 ms |
700 KB |
Output isn't correct |
23 |
Incorrect |
43 ms |
700 KB |
Output isn't correct |
24 |
Incorrect |
49 ms |
700 KB |
Output isn't correct |
25 |
Execution timed out |
5 ms |
700 KB |
Time limit exceeded (wall clock) |
26 |
Execution timed out |
5 ms |
700 KB |
Time limit exceeded (wall clock) |
27 |
Execution timed out |
5 ms |
700 KB |
Time limit exceeded (wall clock) |
28 |
Execution timed out |
5 ms |
700 KB |
Time limit exceeded (wall clock) |
29 |
Execution timed out |
5 ms |
700 KB |
Time limit exceeded (wall clock) |
30 |
Execution timed out |
5 ms |
700 KB |
Time limit exceeded (wall clock) |