#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 {
ll a=ll(x)*R.y, b=ll(y)*R.x;
return a<b || a==b && (i<R.i || i==R.i && j<R.j);
}
};
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};
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 member function 'bool event::operator<(event) const':
bulldozer.cpp:26:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
26 | return a<b || a==b && (i<R.i || i==R.i && j<R.j);
| ~~~~~~~^~~~~~~~
bulldozer.cpp:26:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
26 | return a<b || a==b && (i<R.i || i==R.i && j<R.j);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:33:19: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
33 | const int M=1<<32-__builtin_clz(N);
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 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 |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 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 |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
581 ms |
31876 KB |
Output is correct |
34 |
Correct |
579 ms |
31880 KB |
Output is correct |
35 |
Correct |
577 ms |
31864 KB |
Output is correct |
36 |
Correct |
585 ms |
31880 KB |
Output is correct |
37 |
Correct |
576 ms |
31864 KB |
Output is correct |
38 |
Correct |
580 ms |
31736 KB |
Output is correct |
39 |
Correct |
580 ms |
31736 KB |
Output is correct |
40 |
Correct |
586 ms |
31864 KB |
Output is correct |
41 |
Correct |
569 ms |
31852 KB |
Output is correct |
42 |
Correct |
608 ms |
31848 KB |
Output is correct |
43 |
Correct |
577 ms |
31968 KB |
Output is correct |
44 |
Correct |
581 ms |
31864 KB |
Output is correct |
45 |
Correct |
576 ms |
31864 KB |
Output is correct |
46 |
Correct |
572 ms |
31844 KB |
Output is correct |
47 |
Correct |
572 ms |
31992 KB |
Output is correct |
48 |
Correct |
573 ms |
31864 KB |
Output is correct |
49 |
Correct |
566 ms |
31864 KB |
Output is correct |
50 |
Correct |
574 ms |
31856 KB |
Output is correct |
51 |
Correct |
580 ms |
31740 KB |
Output is correct |
52 |
Correct |
595 ms |
31736 KB |
Output is correct |
53 |
Correct |
565 ms |
31844 KB |
Output is correct |
54 |
Correct |
579 ms |
31844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 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 |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
288 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 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 |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
581 ms |
31876 KB |
Output is correct |
34 |
Correct |
579 ms |
31880 KB |
Output is correct |
35 |
Correct |
577 ms |
31864 KB |
Output is correct |
36 |
Correct |
585 ms |
31880 KB |
Output is correct |
37 |
Correct |
576 ms |
31864 KB |
Output is correct |
38 |
Correct |
580 ms |
31736 KB |
Output is correct |
39 |
Correct |
580 ms |
31736 KB |
Output is correct |
40 |
Correct |
586 ms |
31864 KB |
Output is correct |
41 |
Correct |
569 ms |
31852 KB |
Output is correct |
42 |
Correct |
608 ms |
31848 KB |
Output is correct |
43 |
Correct |
577 ms |
31968 KB |
Output is correct |
44 |
Correct |
581 ms |
31864 KB |
Output is correct |
45 |
Correct |
576 ms |
31864 KB |
Output is correct |
46 |
Correct |
572 ms |
31844 KB |
Output is correct |
47 |
Correct |
572 ms |
31992 KB |
Output is correct |
48 |
Correct |
573 ms |
31864 KB |
Output is correct |
49 |
Correct |
566 ms |
31864 KB |
Output is correct |
50 |
Correct |
574 ms |
31856 KB |
Output is correct |
51 |
Correct |
580 ms |
31740 KB |
Output is correct |
52 |
Correct |
595 ms |
31736 KB |
Output is correct |
53 |
Correct |
565 ms |
31844 KB |
Output is correct |
54 |
Correct |
579 ms |
31844 KB |
Output is correct |
55 |
Correct |
582 ms |
31856 KB |
Output is correct |
56 |
Correct |
574 ms |
31864 KB |
Output is correct |
57 |
Correct |
583 ms |
31868 KB |
Output is correct |
58 |
Correct |
578 ms |
31992 KB |
Output is correct |
59 |
Correct |
570 ms |
31736 KB |
Output is correct |
60 |
Correct |
574 ms |
31868 KB |
Output is correct |
61 |
Correct |
580 ms |
31840 KB |
Output is correct |
62 |
Correct |
598 ms |
31992 KB |
Output is correct |
63 |
Correct |
588 ms |
31864 KB |
Output is correct |
64 |
Correct |
577 ms |
31872 KB |
Output is correct |
65 |
Correct |
583 ms |
31864 KB |
Output is correct |
66 |
Correct |
588 ms |
31864 KB |
Output is correct |
67 |
Correct |
572 ms |
31876 KB |
Output is correct |
68 |
Correct |
585 ms |
31992 KB |
Output is correct |
69 |
Correct |
580 ms |
31864 KB |
Output is correct |
70 |
Correct |
578 ms |
31864 KB |
Output is correct |
71 |
Correct |
582 ms |
31864 KB |
Output is correct |
72 |
Correct |
581 ms |
31864 KB |
Output is correct |
73 |
Correct |
589 ms |
31864 KB |
Output is correct |
74 |
Correct |
573 ms |
31864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |