#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ari2 = array<int, 2>;
#define vt vector
#define size(x) (int((x).size()))
#define all(x) begin(x), end(x)
#define REP(a,b,c,d) for(int a=(b);(d)>0?a<=(c):a>=(c);a+=(d))
#define FOR(a,b,c) REP(a,b,c,1)
#define ROF(a,b,c) REP(a,b,c,-1)
constexpr int mxN = 2005;
int N, X[mxN], Y[mxN], W[mxN];
struct Event {
int y, x, i, j;
Event(int _y, int _x, int _i, int _j) : y(_y), x(_x), i(_i), j(_j) {
if (x < 0)
y = -y, x = -x;
}
};
struct Node {
ll ans, lft, rht, sum;
Node operator+(const Node &other) {
return {
max({ans, other.ans, rht + other.lft}),
max(lft, sum + other.lft),
max(other.rht, other.sum + rht),
sum + other.sum
};
}
};
struct ST {
Node st[mxN<<1];
void update(int i, int v) {
st[i+=N] = {max(v, 0), max(v, 0), max(v, 0), v};
for (i >>= 1; i > 0; i >>= 1)
st[i] = st[i<<1] + st[i<<1|1];
}
Node query(int l, int r) {
Node lft = {0, 0, 0, 0};
Node rht = {0, 0, 0, 0};
for (l += N, r += N+1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
lft = lft + st[l++];
if (r & 1)
rht = st[--r] + rht;
}
return lft + rht;
}
} st;
signed main() {
#ifndef DEBUG
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
cin >> N;
vt<Event> sweep;
FOR(i, 0, N-1)
cin >> X[i] >> Y[i] >> W[i];
FOR(i, 0, N-1)
FOR(j, 0, N-1)
if (i != j && (X[i] > X[j] || X[i] == X[j] && Y[i] > Y[j]))
sweep.push_back(Event(Y[i] - Y[j], X[i] - X[j], i, j));
sort(all(sweep), [&](const Event &a, const Event &b) {
ll va = 1ll * a.y * b.x;
ll vb = 1ll * b.y * a.x;
return va != vb ? va < vb : ari2{-X[a.i], -X[a.j]} < ari2{-X[b.i], -X[b.j]};
});
vt<int> ord(N);
iota(all(ord), 0);
sort(all(ord), [&](const int &a, const int &b) {
return X[a] < X[b];
});
vt<int> pos(N);
FOR(ii, 0, N-1) {
const int i = ord[ii];
pos[i] = ii;
st.update(ii, W[i]);
}
ll ans = st.query(0, N-1).ans;
FOR(k, 0, size(sweep)-1) {
auto [y, x, i, j] = sweep[k];
st.update(pos[i], W[j]);
st.update(pos[j], W[i]);
swap(pos[i], pos[j]);
if (k == size(sweep)-1 || 1ll * y * sweep[k+1].x != 1ll * sweep[k+1].y * x)
ans = max(ans, st.query(0, N-1).ans);
}
cout << ans << '\n';
}
Compilation message
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:68:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
68 | if (i != j && (X[i] > X[j] || X[i] == X[j] && Y[i] > Y[j]))
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
456 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
628 ms |
33408 KB |
Output is correct |
34 |
Correct |
610 ms |
33472 KB |
Output is correct |
35 |
Correct |
575 ms |
33472 KB |
Output is correct |
36 |
Correct |
595 ms |
33512 KB |
Output is correct |
37 |
Correct |
604 ms |
33732 KB |
Output is correct |
38 |
Correct |
584 ms |
33500 KB |
Output is correct |
39 |
Correct |
628 ms |
33468 KB |
Output is correct |
40 |
Correct |
579 ms |
33380 KB |
Output is correct |
41 |
Correct |
609 ms |
33452 KB |
Output is correct |
42 |
Correct |
646 ms |
33724 KB |
Output is correct |
43 |
Correct |
625 ms |
33456 KB |
Output is correct |
44 |
Correct |
584 ms |
33628 KB |
Output is correct |
45 |
Correct |
581 ms |
33468 KB |
Output is correct |
46 |
Correct |
631 ms |
33508 KB |
Output is correct |
47 |
Correct |
593 ms |
33356 KB |
Output is correct |
48 |
Correct |
572 ms |
33468 KB |
Output is correct |
49 |
Correct |
587 ms |
33468 KB |
Output is correct |
50 |
Correct |
598 ms |
33468 KB |
Output is correct |
51 |
Correct |
608 ms |
33464 KB |
Output is correct |
52 |
Correct |
609 ms |
33468 KB |
Output is correct |
53 |
Correct |
596 ms |
33480 KB |
Output is correct |
54 |
Correct |
589 ms |
33468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
628 ms |
33408 KB |
Output is correct |
34 |
Correct |
610 ms |
33472 KB |
Output is correct |
35 |
Correct |
575 ms |
33472 KB |
Output is correct |
36 |
Correct |
595 ms |
33512 KB |
Output is correct |
37 |
Correct |
604 ms |
33732 KB |
Output is correct |
38 |
Correct |
584 ms |
33500 KB |
Output is correct |
39 |
Correct |
628 ms |
33468 KB |
Output is correct |
40 |
Correct |
579 ms |
33380 KB |
Output is correct |
41 |
Correct |
609 ms |
33452 KB |
Output is correct |
42 |
Correct |
646 ms |
33724 KB |
Output is correct |
43 |
Correct |
625 ms |
33456 KB |
Output is correct |
44 |
Correct |
584 ms |
33628 KB |
Output is correct |
45 |
Correct |
581 ms |
33468 KB |
Output is correct |
46 |
Correct |
631 ms |
33508 KB |
Output is correct |
47 |
Correct |
593 ms |
33356 KB |
Output is correct |
48 |
Correct |
572 ms |
33468 KB |
Output is correct |
49 |
Correct |
587 ms |
33468 KB |
Output is correct |
50 |
Correct |
598 ms |
33468 KB |
Output is correct |
51 |
Correct |
608 ms |
33464 KB |
Output is correct |
52 |
Correct |
609 ms |
33468 KB |
Output is correct |
53 |
Correct |
596 ms |
33480 KB |
Output is correct |
54 |
Correct |
589 ms |
33468 KB |
Output is correct |
55 |
Correct |
613 ms |
33476 KB |
Output is correct |
56 |
Correct |
596 ms |
33460 KB |
Output is correct |
57 |
Correct |
615 ms |
33480 KB |
Output is correct |
58 |
Correct |
590 ms |
33288 KB |
Output is correct |
59 |
Correct |
623 ms |
33472 KB |
Output is correct |
60 |
Correct |
603 ms |
33496 KB |
Output is correct |
61 |
Correct |
583 ms |
33372 KB |
Output is correct |
62 |
Correct |
620 ms |
33472 KB |
Output is correct |
63 |
Correct |
592 ms |
33480 KB |
Output is correct |
64 |
Correct |
593 ms |
33468 KB |
Output is correct |
65 |
Incorrect |
589 ms |
33468 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
456 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
2 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
600 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
460 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
628 ms |
33408 KB |
Output is correct |
49 |
Correct |
610 ms |
33472 KB |
Output is correct |
50 |
Correct |
575 ms |
33472 KB |
Output is correct |
51 |
Correct |
595 ms |
33512 KB |
Output is correct |
52 |
Correct |
604 ms |
33732 KB |
Output is correct |
53 |
Correct |
584 ms |
33500 KB |
Output is correct |
54 |
Correct |
628 ms |
33468 KB |
Output is correct |
55 |
Correct |
579 ms |
33380 KB |
Output is correct |
56 |
Correct |
609 ms |
33452 KB |
Output is correct |
57 |
Correct |
646 ms |
33724 KB |
Output is correct |
58 |
Correct |
625 ms |
33456 KB |
Output is correct |
59 |
Correct |
584 ms |
33628 KB |
Output is correct |
60 |
Correct |
581 ms |
33468 KB |
Output is correct |
61 |
Correct |
631 ms |
33508 KB |
Output is correct |
62 |
Correct |
593 ms |
33356 KB |
Output is correct |
63 |
Correct |
572 ms |
33468 KB |
Output is correct |
64 |
Correct |
587 ms |
33468 KB |
Output is correct |
65 |
Correct |
598 ms |
33468 KB |
Output is correct |
66 |
Correct |
608 ms |
33464 KB |
Output is correct |
67 |
Correct |
609 ms |
33468 KB |
Output is correct |
68 |
Correct |
596 ms |
33480 KB |
Output is correct |
69 |
Correct |
589 ms |
33468 KB |
Output is correct |
70 |
Correct |
613 ms |
33476 KB |
Output is correct |
71 |
Correct |
596 ms |
33460 KB |
Output is correct |
72 |
Correct |
615 ms |
33480 KB |
Output is correct |
73 |
Correct |
590 ms |
33288 KB |
Output is correct |
74 |
Correct |
623 ms |
33472 KB |
Output is correct |
75 |
Correct |
603 ms |
33496 KB |
Output is correct |
76 |
Correct |
583 ms |
33372 KB |
Output is correct |
77 |
Correct |
620 ms |
33472 KB |
Output is correct |
78 |
Correct |
592 ms |
33480 KB |
Output is correct |
79 |
Correct |
593 ms |
33468 KB |
Output is correct |
80 |
Incorrect |
589 ms |
33468 KB |
Output isn't correct |
81 |
Halted |
0 ms |
0 KB |
- |