#include <bits/stdc++.h>
using namespace std;
using ll=long long;
struct node {
ll mx, lm, rm, sum;
node operator+(const node R) const {
return {
max({mx, R.mx, rm+R.lm}),
max(lm, sum+R.lm),
max(R.rm, rm+R.sum),
sum+R.sum
};
}
};
struct spot {
int x, y, w;
bool operator<(const spot R) const {
return x<R.x || x==R.x && y<R.y;
}
};
struct event {
int x, y, i, j;
bool operator<(const event R) const {
return ll(x)*R.y<ll(y)*R.x;
}
};
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int N, K=0;
cin>>N;
const int M=1<<32-__builtin_clz(N);
vector<spot> A(N);
for(auto&[x,y,w]:A) cin>>x>>y>>w;
sort(begin(A), end(A));
vector<event> E(N*(N-1)/2);
for(int i=0; i<N; i++) for(int j=0; j<i; j++)
E[K++]={A[i].x-A[j].x, A[i].y-A[j].y, j, i};
stable_sort(begin(E), end(E));
vector<node> T(M*2);
auto upd=[&](int i, int x) {
for(T[i+=M]={x, x, x, x}; i>>=1;)
T[i]=T[i*2]+T[i*2+1];
};
for(int i=0; i<N; i++) {
int x=A[i].w;
T[i+M]={x, x, x, x};
}
for(int i=M; i--;)
T[i]=T[i*2]+T[i*2+1];
ll mx=T[1].mx;
vector<int> P(N);
iota(begin(P), end(P), 0);
for(int k=0; k<K; k++) {
auto[x,y,i,j]=E[k];
swap(P[i], P[j]);
upd(P[i], A[i].w);
upd(P[j], A[j].w);
if(k+1<K && !(E[k]<E[k+1])) continue;
mx=max(mx, T[1].mx);
}
cout<<max(mx, ll(0))<<'\n';
}
Compilation message
bulldozer.cpp: In member function 'bool spot::operator<(spot) const':
bulldozer.cpp:19:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
19 | return x<R.x || x==R.x && y<R.y;
| ~~~~~~~^~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:32:19: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
32 | const int M=1<<32-__builtin_clz(N);
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
636 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
508 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
508 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
508 KB |
Output is correct |
24 |
Correct |
2 ms |
416 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
508 KB |
Output is correct |
28 |
Correct |
1 ms |
508 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
508 KB |
Output is correct |
31 |
Correct |
1 ms |
508 KB |
Output is correct |
32 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
508 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
508 KB |
Output is correct |
24 |
Correct |
2 ms |
416 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
508 KB |
Output is correct |
28 |
Correct |
1 ms |
508 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
508 KB |
Output is correct |
31 |
Correct |
1 ms |
508 KB |
Output is correct |
32 |
Correct |
2 ms |
508 KB |
Output is correct |
33 |
Correct |
561 ms |
47372 KB |
Output is correct |
34 |
Correct |
565 ms |
47480 KB |
Output is correct |
35 |
Correct |
563 ms |
47352 KB |
Output is correct |
36 |
Correct |
581 ms |
47372 KB |
Output is correct |
37 |
Correct |
563 ms |
47352 KB |
Output is correct |
38 |
Correct |
577 ms |
47368 KB |
Output is correct |
39 |
Correct |
558 ms |
47480 KB |
Output is correct |
40 |
Correct |
588 ms |
47372 KB |
Output is correct |
41 |
Correct |
575 ms |
47480 KB |
Output is correct |
42 |
Correct |
571 ms |
47352 KB |
Output is correct |
43 |
Correct |
571 ms |
47352 KB |
Output is correct |
44 |
Correct |
554 ms |
47376 KB |
Output is correct |
45 |
Correct |
550 ms |
47352 KB |
Output is correct |
46 |
Correct |
555 ms |
47356 KB |
Output is correct |
47 |
Correct |
553 ms |
47352 KB |
Output is correct |
48 |
Correct |
552 ms |
47352 KB |
Output is correct |
49 |
Correct |
560 ms |
47440 KB |
Output is correct |
50 |
Correct |
566 ms |
47356 KB |
Output is correct |
51 |
Correct |
574 ms |
47480 KB |
Output is correct |
52 |
Correct |
558 ms |
47352 KB |
Output is correct |
53 |
Correct |
559 ms |
47480 KB |
Output is correct |
54 |
Correct |
579 ms |
47480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
508 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
508 KB |
Output is correct |
24 |
Correct |
2 ms |
416 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
508 KB |
Output is correct |
28 |
Correct |
1 ms |
508 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
508 KB |
Output is correct |
31 |
Correct |
1 ms |
508 KB |
Output is correct |
32 |
Correct |
2 ms |
508 KB |
Output is correct |
33 |
Correct |
561 ms |
47372 KB |
Output is correct |
34 |
Correct |
565 ms |
47480 KB |
Output is correct |
35 |
Correct |
563 ms |
47352 KB |
Output is correct |
36 |
Correct |
581 ms |
47372 KB |
Output is correct |
37 |
Correct |
563 ms |
47352 KB |
Output is correct |
38 |
Correct |
577 ms |
47368 KB |
Output is correct |
39 |
Correct |
558 ms |
47480 KB |
Output is correct |
40 |
Correct |
588 ms |
47372 KB |
Output is correct |
41 |
Correct |
575 ms |
47480 KB |
Output is correct |
42 |
Correct |
571 ms |
47352 KB |
Output is correct |
43 |
Correct |
571 ms |
47352 KB |
Output is correct |
44 |
Correct |
554 ms |
47376 KB |
Output is correct |
45 |
Correct |
550 ms |
47352 KB |
Output is correct |
46 |
Correct |
555 ms |
47356 KB |
Output is correct |
47 |
Correct |
553 ms |
47352 KB |
Output is correct |
48 |
Correct |
552 ms |
47352 KB |
Output is correct |
49 |
Correct |
560 ms |
47440 KB |
Output is correct |
50 |
Correct |
566 ms |
47356 KB |
Output is correct |
51 |
Correct |
574 ms |
47480 KB |
Output is correct |
52 |
Correct |
558 ms |
47352 KB |
Output is correct |
53 |
Correct |
559 ms |
47480 KB |
Output is correct |
54 |
Correct |
579 ms |
47480 KB |
Output is correct |
55 |
Correct |
571 ms |
47480 KB |
Output is correct |
56 |
Correct |
568 ms |
47352 KB |
Output is correct |
57 |
Correct |
585 ms |
47480 KB |
Output is correct |
58 |
Correct |
571 ms |
47480 KB |
Output is correct |
59 |
Correct |
566 ms |
47352 KB |
Output is correct |
60 |
Correct |
560 ms |
47352 KB |
Output is correct |
61 |
Correct |
569 ms |
47352 KB |
Output is correct |
62 |
Correct |
571 ms |
47352 KB |
Output is correct |
63 |
Correct |
560 ms |
47352 KB |
Output is correct |
64 |
Correct |
565 ms |
47352 KB |
Output is correct |
65 |
Correct |
562 ms |
47352 KB |
Output is correct |
66 |
Correct |
569 ms |
47480 KB |
Output is correct |
67 |
Correct |
575 ms |
47352 KB |
Output is correct |
68 |
Correct |
564 ms |
47480 KB |
Output is correct |
69 |
Correct |
559 ms |
47352 KB |
Output is correct |
70 |
Correct |
568 ms |
47352 KB |
Output is correct |
71 |
Correct |
562 ms |
47356 KB |
Output is correct |
72 |
Correct |
556 ms |
47352 KB |
Output is correct |
73 |
Correct |
578 ms |
47352 KB |
Output is correct |
74 |
Correct |
563 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
636 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
508 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
508 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
508 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
508 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
0 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
2 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
508 KB |
Output is correct |
39 |
Correct |
2 ms |
416 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
1 ms |
384 KB |
Output is correct |
42 |
Correct |
1 ms |
508 KB |
Output is correct |
43 |
Correct |
1 ms |
508 KB |
Output is correct |
44 |
Correct |
2 ms |
512 KB |
Output is correct |
45 |
Correct |
1 ms |
508 KB |
Output is correct |
46 |
Correct |
1 ms |
508 KB |
Output is correct |
47 |
Correct |
2 ms |
508 KB |
Output is correct |
48 |
Correct |
561 ms |
47372 KB |
Output is correct |
49 |
Correct |
565 ms |
47480 KB |
Output is correct |
50 |
Correct |
563 ms |
47352 KB |
Output is correct |
51 |
Correct |
581 ms |
47372 KB |
Output is correct |
52 |
Correct |
563 ms |
47352 KB |
Output is correct |
53 |
Correct |
577 ms |
47368 KB |
Output is correct |
54 |
Correct |
558 ms |
47480 KB |
Output is correct |
55 |
Correct |
588 ms |
47372 KB |
Output is correct |
56 |
Correct |
575 ms |
47480 KB |
Output is correct |
57 |
Correct |
571 ms |
47352 KB |
Output is correct |
58 |
Correct |
571 ms |
47352 KB |
Output is correct |
59 |
Correct |
554 ms |
47376 KB |
Output is correct |
60 |
Correct |
550 ms |
47352 KB |
Output is correct |
61 |
Correct |
555 ms |
47356 KB |
Output is correct |
62 |
Correct |
553 ms |
47352 KB |
Output is correct |
63 |
Correct |
552 ms |
47352 KB |
Output is correct |
64 |
Correct |
560 ms |
47440 KB |
Output is correct |
65 |
Correct |
566 ms |
47356 KB |
Output is correct |
66 |
Correct |
574 ms |
47480 KB |
Output is correct |
67 |
Correct |
558 ms |
47352 KB |
Output is correct |
68 |
Correct |
559 ms |
47480 KB |
Output is correct |
69 |
Correct |
579 ms |
47480 KB |
Output is correct |
70 |
Correct |
571 ms |
47480 KB |
Output is correct |
71 |
Correct |
568 ms |
47352 KB |
Output is correct |
72 |
Correct |
585 ms |
47480 KB |
Output is correct |
73 |
Correct |
571 ms |
47480 KB |
Output is correct |
74 |
Correct |
566 ms |
47352 KB |
Output is correct |
75 |
Correct |
560 ms |
47352 KB |
Output is correct |
76 |
Correct |
569 ms |
47352 KB |
Output is correct |
77 |
Correct |
571 ms |
47352 KB |
Output is correct |
78 |
Correct |
560 ms |
47352 KB |
Output is correct |
79 |
Correct |
565 ms |
47352 KB |
Output is correct |
80 |
Correct |
562 ms |
47352 KB |
Output is correct |
81 |
Correct |
569 ms |
47480 KB |
Output is correct |
82 |
Correct |
575 ms |
47352 KB |
Output is correct |
83 |
Correct |
564 ms |
47480 KB |
Output is correct |
84 |
Correct |
559 ms |
47352 KB |
Output is correct |
85 |
Correct |
568 ms |
47352 KB |
Output is correct |
86 |
Correct |
562 ms |
47356 KB |
Output is correct |
87 |
Correct |
556 ms |
47352 KB |
Output is correct |
88 |
Correct |
578 ms |
47352 KB |
Output is correct |
89 |
Correct |
563 ms |
47352 KB |
Output is correct |
90 |
Correct |
565 ms |
47364 KB |
Output is correct |
91 |
Correct |
583 ms |
47368 KB |
Output is correct |
92 |
Correct |
590 ms |
47480 KB |
Output is correct |
93 |
Correct |
567 ms |
47464 KB |
Output is correct |
94 |
Correct |
563 ms |
47352 KB |
Output is correct |
95 |
Correct |
561 ms |
47352 KB |
Output is correct |
96 |
Correct |
563 ms |
47480 KB |
Output is correct |
97 |
Correct |
586 ms |
47480 KB |
Output is correct |
98 |
Correct |
565 ms |
47352 KB |
Output is correct |
99 |
Correct |
562 ms |
47352 KB |
Output is correct |
100 |
Correct |
440 ms |
47360 KB |
Output is correct |
101 |
Correct |
430 ms |
47352 KB |
Output is correct |
102 |
Correct |
435 ms |
47352 KB |
Output is correct |
103 |
Correct |
437 ms |
47352 KB |
Output is correct |
104 |
Correct |
438 ms |
47352 KB |
Output is correct |
105 |
Correct |
458 ms |
47480 KB |
Output is correct |
106 |
Correct |
463 ms |
47352 KB |
Output is correct |
107 |
Correct |
462 ms |
47480 KB |
Output is correct |
108 |
Correct |
455 ms |
47360 KB |
Output is correct |
109 |
Correct |
468 ms |
47352 KB |
Output is correct |
110 |
Correct |
432 ms |
47352 KB |
Output is correct |
111 |
Correct |
439 ms |
47480 KB |
Output is correct |
112 |
Correct |
432 ms |
47360 KB |
Output is correct |
113 |
Correct |
475 ms |
47480 KB |
Output is correct |
114 |
Correct |
436 ms |
47480 KB |
Output is correct |
115 |
Correct |
424 ms |
47352 KB |
Output is correct |
116 |
Correct |
430 ms |
47360 KB |
Output is correct |
117 |
Correct |
425 ms |
47352 KB |
Output is correct |
118 |
Correct |
428 ms |
47480 KB |
Output is correct |
119 |
Correct |
456 ms |
47352 KB |
Output is correct |
120 |
Correct |
1 ms |
384 KB |
Output is correct |
121 |
Correct |
0 ms |
384 KB |
Output is correct |
122 |
Correct |
564 ms |
47352 KB |
Output is correct |
123 |
Correct |
554 ms |
47352 KB |
Output is correct |
124 |
Correct |
547 ms |
47352 KB |
Output is correct |
125 |
Correct |
555 ms |
47352 KB |
Output is correct |
126 |
Correct |
558 ms |
47480 KB |
Output is correct |
127 |
Correct |
559 ms |
47480 KB |
Output is correct |
128 |
Correct |
567 ms |
47352 KB |
Output is correct |
129 |
Correct |
575 ms |
47480 KB |
Output is correct |
130 |
Correct |
592 ms |
47480 KB |
Output is correct |
131 |
Correct |
552 ms |
47480 KB |
Output is correct |
132 |
Correct |
557 ms |
47352 KB |
Output is correct |
133 |
Correct |
549 ms |
47352 KB |
Output is correct |