#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;
bool operator<(const event R) const {
ll a=ll(x)*R.y, b=ll(y)*R.x;
return a<b || a==b && i<R.i;
}
};
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int N, K=0;
cin>>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, i<<16|j};
sort(begin(E), end(E));
vector<node> T(4096);
auto upd=[&](int i, int x) {
for(T[i|=2048]={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+2048]={x, x, x, x};
}
for(int i=2048; 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,t]=E[k];
int i=t>>16, j=t&65535;
swap(P[i], P[j]);
upd(P[i], A[i].w);
upd(P[j], A[j].w);
if(k+1<K && ll(E[k].x)*E[k+1].y==ll(E[k+1].x)*E[k].y) continue;
mx=max(mx, T[1].mx);
}
cout<<mx<<'\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 member function 'bool event::operator<(event) const':
bulldozer.cpp:26:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
26 | return a<b || a==b && i<R.i;
| ~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
544 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
0 ms |
512 KB |
Output is correct |
17 |
Correct |
0 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
0 ms |
512 KB |
Output is correct |
20 |
Correct |
0 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
2 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
0 ms |
512 KB |
Output is correct |
17 |
Correct |
0 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
0 ms |
512 KB |
Output is correct |
20 |
Correct |
0 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
2 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
33 |
Correct |
585 ms |
24024 KB |
Output is correct |
34 |
Correct |
573 ms |
24056 KB |
Output is correct |
35 |
Correct |
603 ms |
24024 KB |
Output is correct |
36 |
Correct |
579 ms |
23928 KB |
Output is correct |
37 |
Correct |
577 ms |
24056 KB |
Output is correct |
38 |
Correct |
574 ms |
24056 KB |
Output is correct |
39 |
Correct |
578 ms |
24020 KB |
Output is correct |
40 |
Correct |
573 ms |
23928 KB |
Output is correct |
41 |
Correct |
573 ms |
24056 KB |
Output is correct |
42 |
Correct |
574 ms |
24056 KB |
Output is correct |
43 |
Correct |
585 ms |
23928 KB |
Output is correct |
44 |
Correct |
589 ms |
23928 KB |
Output is correct |
45 |
Correct |
579 ms |
23928 KB |
Output is correct |
46 |
Correct |
574 ms |
23928 KB |
Output is correct |
47 |
Correct |
569 ms |
23928 KB |
Output is correct |
48 |
Correct |
592 ms |
23928 KB |
Output is correct |
49 |
Correct |
589 ms |
24148 KB |
Output is correct |
50 |
Correct |
606 ms |
24056 KB |
Output is correct |
51 |
Correct |
570 ms |
24056 KB |
Output is correct |
52 |
Correct |
601 ms |
24184 KB |
Output is correct |
53 |
Correct |
569 ms |
24060 KB |
Output is correct |
54 |
Correct |
576 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
0 ms |
512 KB |
Output is correct |
17 |
Correct |
0 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
0 ms |
512 KB |
Output is correct |
20 |
Correct |
0 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
2 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
33 |
Correct |
585 ms |
24024 KB |
Output is correct |
34 |
Correct |
573 ms |
24056 KB |
Output is correct |
35 |
Correct |
603 ms |
24024 KB |
Output is correct |
36 |
Correct |
579 ms |
23928 KB |
Output is correct |
37 |
Correct |
577 ms |
24056 KB |
Output is correct |
38 |
Correct |
574 ms |
24056 KB |
Output is correct |
39 |
Correct |
578 ms |
24020 KB |
Output is correct |
40 |
Correct |
573 ms |
23928 KB |
Output is correct |
41 |
Correct |
573 ms |
24056 KB |
Output is correct |
42 |
Correct |
574 ms |
24056 KB |
Output is correct |
43 |
Correct |
585 ms |
23928 KB |
Output is correct |
44 |
Correct |
589 ms |
23928 KB |
Output is correct |
45 |
Correct |
579 ms |
23928 KB |
Output is correct |
46 |
Correct |
574 ms |
23928 KB |
Output is correct |
47 |
Correct |
569 ms |
23928 KB |
Output is correct |
48 |
Correct |
592 ms |
23928 KB |
Output is correct |
49 |
Correct |
589 ms |
24148 KB |
Output is correct |
50 |
Correct |
606 ms |
24056 KB |
Output is correct |
51 |
Correct |
570 ms |
24056 KB |
Output is correct |
52 |
Correct |
601 ms |
24184 KB |
Output is correct |
53 |
Correct |
569 ms |
24060 KB |
Output is correct |
54 |
Correct |
576 ms |
23928 KB |
Output is correct |
55 |
Correct |
574 ms |
24016 KB |
Output is correct |
56 |
Correct |
578 ms |
24068 KB |
Output is correct |
57 |
Correct |
577 ms |
24056 KB |
Output is correct |
58 |
Correct |
581 ms |
23928 KB |
Output is correct |
59 |
Correct |
573 ms |
23928 KB |
Output is correct |
60 |
Correct |
573 ms |
24028 KB |
Output is correct |
61 |
Correct |
571 ms |
24036 KB |
Output is correct |
62 |
Correct |
578 ms |
24056 KB |
Output is correct |
63 |
Correct |
587 ms |
24184 KB |
Output is correct |
64 |
Correct |
573 ms |
24020 KB |
Output is correct |
65 |
Correct |
583 ms |
24184 KB |
Output is correct |
66 |
Correct |
578 ms |
24056 KB |
Output is correct |
67 |
Correct |
578 ms |
24068 KB |
Output is correct |
68 |
Correct |
582 ms |
24056 KB |
Output is correct |
69 |
Correct |
577 ms |
24056 KB |
Output is correct |
70 |
Correct |
613 ms |
24184 KB |
Output is correct |
71 |
Correct |
618 ms |
24148 KB |
Output is correct |
72 |
Correct |
578 ms |
24056 KB |
Output is correct |
73 |
Correct |
581 ms |
24016 KB |
Output is correct |
74 |
Correct |
587 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
544 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Correct |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
0 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
0 ms |
512 KB |
Output is correct |
30 |
Correct |
0 ms |
512 KB |
Output is correct |
31 |
Correct |
0 ms |
512 KB |
Output is correct |
32 |
Correct |
0 ms |
512 KB |
Output is correct |
33 |
Correct |
1 ms |
512 KB |
Output is correct |
34 |
Correct |
0 ms |
512 KB |
Output is correct |
35 |
Correct |
0 ms |
512 KB |
Output is correct |
36 |
Correct |
2 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
2 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
2 ms |
512 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
512 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
512 KB |
Output is correct |
47 |
Correct |
2 ms |
512 KB |
Output is correct |
48 |
Correct |
585 ms |
24024 KB |
Output is correct |
49 |
Correct |
573 ms |
24056 KB |
Output is correct |
50 |
Correct |
603 ms |
24024 KB |
Output is correct |
51 |
Correct |
579 ms |
23928 KB |
Output is correct |
52 |
Correct |
577 ms |
24056 KB |
Output is correct |
53 |
Correct |
574 ms |
24056 KB |
Output is correct |
54 |
Correct |
578 ms |
24020 KB |
Output is correct |
55 |
Correct |
573 ms |
23928 KB |
Output is correct |
56 |
Correct |
573 ms |
24056 KB |
Output is correct |
57 |
Correct |
574 ms |
24056 KB |
Output is correct |
58 |
Correct |
585 ms |
23928 KB |
Output is correct |
59 |
Correct |
589 ms |
23928 KB |
Output is correct |
60 |
Correct |
579 ms |
23928 KB |
Output is correct |
61 |
Correct |
574 ms |
23928 KB |
Output is correct |
62 |
Correct |
569 ms |
23928 KB |
Output is correct |
63 |
Correct |
592 ms |
23928 KB |
Output is correct |
64 |
Correct |
589 ms |
24148 KB |
Output is correct |
65 |
Correct |
606 ms |
24056 KB |
Output is correct |
66 |
Correct |
570 ms |
24056 KB |
Output is correct |
67 |
Correct |
601 ms |
24184 KB |
Output is correct |
68 |
Correct |
569 ms |
24060 KB |
Output is correct |
69 |
Correct |
576 ms |
23928 KB |
Output is correct |
70 |
Correct |
574 ms |
24016 KB |
Output is correct |
71 |
Correct |
578 ms |
24068 KB |
Output is correct |
72 |
Correct |
577 ms |
24056 KB |
Output is correct |
73 |
Correct |
581 ms |
23928 KB |
Output is correct |
74 |
Correct |
573 ms |
23928 KB |
Output is correct |
75 |
Correct |
573 ms |
24028 KB |
Output is correct |
76 |
Correct |
571 ms |
24036 KB |
Output is correct |
77 |
Correct |
578 ms |
24056 KB |
Output is correct |
78 |
Correct |
587 ms |
24184 KB |
Output is correct |
79 |
Correct |
573 ms |
24020 KB |
Output is correct |
80 |
Correct |
583 ms |
24184 KB |
Output is correct |
81 |
Correct |
578 ms |
24056 KB |
Output is correct |
82 |
Correct |
578 ms |
24068 KB |
Output is correct |
83 |
Correct |
582 ms |
24056 KB |
Output is correct |
84 |
Correct |
577 ms |
24056 KB |
Output is correct |
85 |
Correct |
613 ms |
24184 KB |
Output is correct |
86 |
Correct |
618 ms |
24148 KB |
Output is correct |
87 |
Correct |
578 ms |
24056 KB |
Output is correct |
88 |
Correct |
581 ms |
24016 KB |
Output is correct |
89 |
Correct |
587 ms |
24056 KB |
Output is correct |
90 |
Correct |
583 ms |
24024 KB |
Output is correct |
91 |
Correct |
594 ms |
24056 KB |
Output is correct |
92 |
Correct |
582 ms |
23928 KB |
Output is correct |
93 |
Correct |
587 ms |
23928 KB |
Output is correct |
94 |
Correct |
572 ms |
24056 KB |
Output is correct |
95 |
Correct |
573 ms |
24056 KB |
Output is correct |
96 |
Correct |
619 ms |
23928 KB |
Output is correct |
97 |
Correct |
578 ms |
23928 KB |
Output is correct |
98 |
Correct |
572 ms |
24056 KB |
Output is correct |
99 |
Correct |
575 ms |
24016 KB |
Output is correct |
100 |
Correct |
449 ms |
23928 KB |
Output is correct |
101 |
Correct |
448 ms |
24036 KB |
Output is correct |
102 |
Correct |
438 ms |
24036 KB |
Output is correct |
103 |
Correct |
492 ms |
24056 KB |
Output is correct |
104 |
Correct |
488 ms |
24056 KB |
Output is correct |
105 |
Correct |
470 ms |
24056 KB |
Output is correct |
106 |
Correct |
483 ms |
23928 KB |
Output is correct |
107 |
Correct |
468 ms |
24060 KB |
Output is correct |
108 |
Correct |
481 ms |
24152 KB |
Output is correct |
109 |
Correct |
468 ms |
23928 KB |
Output is correct |
110 |
Correct |
545 ms |
24148 KB |
Output is correct |
111 |
Correct |
572 ms |
24068 KB |
Output is correct |
112 |
Correct |
545 ms |
23928 KB |
Output is correct |
113 |
Correct |
544 ms |
24148 KB |
Output is correct |
114 |
Correct |
553 ms |
23928 KB |
Output is correct |
115 |
Correct |
543 ms |
24020 KB |
Output is correct |
116 |
Correct |
596 ms |
23928 KB |
Output is correct |
117 |
Correct |
553 ms |
23928 KB |
Output is correct |
118 |
Correct |
538 ms |
23932 KB |
Output is correct |
119 |
Correct |
551 ms |
24056 KB |
Output is correct |
120 |
Correct |
1 ms |
512 KB |
Output is correct |
121 |
Correct |
1 ms |
512 KB |
Output is correct |
122 |
Correct |
601 ms |
24056 KB |
Output is correct |
123 |
Correct |
582 ms |
24024 KB |
Output is correct |
124 |
Correct |
587 ms |
24056 KB |
Output is correct |
125 |
Correct |
582 ms |
24184 KB |
Output is correct |
126 |
Correct |
583 ms |
24056 KB |
Output is correct |
127 |
Correct |
579 ms |
24056 KB |
Output is correct |
128 |
Correct |
578 ms |
24184 KB |
Output is correct |
129 |
Correct |
584 ms |
24068 KB |
Output is correct |
130 |
Correct |
580 ms |
24056 KB |
Output is correct |
131 |
Correct |
583 ms |
24056 KB |
Output is correct |
132 |
Correct |
584 ms |
24056 KB |
Output is correct |
133 |
Correct |
600 ms |
24056 KB |
Output is correct |