#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=2e3;
int n, p[mxN], l[mxN];
ll x[mxN], y[mxN], w[mxN], ans;
array<ll, 4> st[1<<12];
array<ll, 6> ss[mxN*(mxN-1)/2];
void upd(int l1, ll x, int i=1, int l2=0, int r2=n-1) {
if(l2==r2) {
st[i]={x, max(x, 0ll), max(x, 0ll), max(x, 0ll)};
return;
}
int m2=(l2+r2)/2;
if(l1<=m2)
upd(l1, x, 2*i, l2, m2);
else
upd(l1, x, 2*i+1, m2+1, r2);
st[i]={st[2*i][0]+st[2*i+1][0], max(st[2*i][1], st[2*i][0]+st[2*i+1][1]), max(st[2*i+1][2], st[2*i+1][0]+st[2*i][2]), max({st[2*i][3], st[2*i+1][3], st[2*i][2]+st[2*i+1][1]})};
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i=0; i<n; ++i) {
cin >> x[i] >> y[i] >> w[i];
p[i]=i;
}
for(int i=0, k=0; i<n; ++i)
for(int j=0; j<n; ++j)
if(i!=j&&(x[i]<x[j]||x[i]==x[j]&&y[i]>y[j]))
ss[k++]={y[j]-y[i], x[j]-x[i], x[i]==x[j]?y[j]:-x[j], x[i]==x[j]?y[i]:-x[i], i, j};
sort(p, p+n, [&](const int &a, const int b) {
return x[a]==x[b]?y[a]<y[b]:x[a]<x[b];
});
for(int i=0; i<n; ++i) {
upd(i, w[p[i]]);
l[p[i]]=i;
}
sort(ss, ss+n*(n-1)/2, [&](const array<ll, 6> &a, const array<ll, 6> &b) {
ll c=a[0]*b[1]-a[1]*b[0];
return c?c<0:array<ll, 2>{a[2], a[3]}<array<ll, 2>{b[2], b[3]};
});
ans=st[1][3];
for(int i=0; i<n*(n-1)/2; ++i) {
int u=ss[i][4], v=ss[i][5];
swap(l[u], l[v]);
upd(l[u], w[u]);
upd(l[v], w[v]);
if(i>=n*(n-1)/2-1||ss[i][0]*ss[i+1][1]<ss[i][1]*ss[i+1][0])
ans=max(st[1][3], ans);
}
cout << ans;
}
Compilation message
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:36:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if(i!=j&&(x[i]<x[j]||x[i]==x[j]&&y[i]>y[j]))
~~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
316 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
640 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
3 ms |
640 KB |
Output is correct |
24 |
Correct |
3 ms |
612 KB |
Output is correct |
25 |
Correct |
3 ms |
640 KB |
Output is correct |
26 |
Correct |
3 ms |
640 KB |
Output is correct |
27 |
Correct |
3 ms |
640 KB |
Output is correct |
28 |
Correct |
3 ms |
640 KB |
Output is correct |
29 |
Correct |
3 ms |
640 KB |
Output is correct |
30 |
Correct |
3 ms |
640 KB |
Output is correct |
31 |
Correct |
3 ms |
640 KB |
Output is correct |
32 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
640 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
3 ms |
640 KB |
Output is correct |
24 |
Correct |
3 ms |
612 KB |
Output is correct |
25 |
Correct |
3 ms |
640 KB |
Output is correct |
26 |
Correct |
3 ms |
640 KB |
Output is correct |
27 |
Correct |
3 ms |
640 KB |
Output is correct |
28 |
Correct |
3 ms |
640 KB |
Output is correct |
29 |
Correct |
3 ms |
640 KB |
Output is correct |
30 |
Correct |
3 ms |
640 KB |
Output is correct |
31 |
Correct |
3 ms |
640 KB |
Output is correct |
32 |
Correct |
3 ms |
640 KB |
Output is correct |
33 |
Correct |
836 ms |
94460 KB |
Output is correct |
34 |
Correct |
838 ms |
94456 KB |
Output is correct |
35 |
Correct |
829 ms |
94460 KB |
Output is correct |
36 |
Correct |
838 ms |
94460 KB |
Output is correct |
37 |
Correct |
878 ms |
94456 KB |
Output is correct |
38 |
Correct |
820 ms |
94452 KB |
Output is correct |
39 |
Correct |
832 ms |
94452 KB |
Output is correct |
40 |
Correct |
840 ms |
94452 KB |
Output is correct |
41 |
Correct |
861 ms |
94452 KB |
Output is correct |
42 |
Correct |
860 ms |
94452 KB |
Output is correct |
43 |
Correct |
837 ms |
94456 KB |
Output is correct |
44 |
Correct |
841 ms |
94456 KB |
Output is correct |
45 |
Correct |
822 ms |
94492 KB |
Output is correct |
46 |
Correct |
834 ms |
94464 KB |
Output is correct |
47 |
Correct |
820 ms |
94456 KB |
Output is correct |
48 |
Correct |
825 ms |
94456 KB |
Output is correct |
49 |
Correct |
812 ms |
94452 KB |
Output is correct |
50 |
Correct |
834 ms |
94456 KB |
Output is correct |
51 |
Correct |
815 ms |
94456 KB |
Output is correct |
52 |
Correct |
825 ms |
94456 KB |
Output is correct |
53 |
Correct |
822 ms |
94464 KB |
Output is correct |
54 |
Correct |
818 ms |
94456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
640 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
3 ms |
640 KB |
Output is correct |
24 |
Correct |
3 ms |
612 KB |
Output is correct |
25 |
Correct |
3 ms |
640 KB |
Output is correct |
26 |
Correct |
3 ms |
640 KB |
Output is correct |
27 |
Correct |
3 ms |
640 KB |
Output is correct |
28 |
Correct |
3 ms |
640 KB |
Output is correct |
29 |
Correct |
3 ms |
640 KB |
Output is correct |
30 |
Correct |
3 ms |
640 KB |
Output is correct |
31 |
Correct |
3 ms |
640 KB |
Output is correct |
32 |
Correct |
3 ms |
640 KB |
Output is correct |
33 |
Correct |
836 ms |
94460 KB |
Output is correct |
34 |
Correct |
838 ms |
94456 KB |
Output is correct |
35 |
Correct |
829 ms |
94460 KB |
Output is correct |
36 |
Correct |
838 ms |
94460 KB |
Output is correct |
37 |
Correct |
878 ms |
94456 KB |
Output is correct |
38 |
Correct |
820 ms |
94452 KB |
Output is correct |
39 |
Correct |
832 ms |
94452 KB |
Output is correct |
40 |
Correct |
840 ms |
94452 KB |
Output is correct |
41 |
Correct |
861 ms |
94452 KB |
Output is correct |
42 |
Correct |
860 ms |
94452 KB |
Output is correct |
43 |
Correct |
837 ms |
94456 KB |
Output is correct |
44 |
Correct |
841 ms |
94456 KB |
Output is correct |
45 |
Correct |
822 ms |
94492 KB |
Output is correct |
46 |
Correct |
834 ms |
94464 KB |
Output is correct |
47 |
Correct |
820 ms |
94456 KB |
Output is correct |
48 |
Correct |
825 ms |
94456 KB |
Output is correct |
49 |
Correct |
812 ms |
94452 KB |
Output is correct |
50 |
Correct |
834 ms |
94456 KB |
Output is correct |
51 |
Correct |
815 ms |
94456 KB |
Output is correct |
52 |
Correct |
825 ms |
94456 KB |
Output is correct |
53 |
Correct |
822 ms |
94464 KB |
Output is correct |
54 |
Correct |
818 ms |
94456 KB |
Output is correct |
55 |
Correct |
829 ms |
94452 KB |
Output is correct |
56 |
Correct |
845 ms |
94456 KB |
Output is correct |
57 |
Correct |
822 ms |
94328 KB |
Output is correct |
58 |
Correct |
850 ms |
94456 KB |
Output is correct |
59 |
Correct |
833 ms |
94460 KB |
Output is correct |
60 |
Correct |
834 ms |
94456 KB |
Output is correct |
61 |
Correct |
827 ms |
94460 KB |
Output is correct |
62 |
Correct |
830 ms |
94456 KB |
Output is correct |
63 |
Correct |
858 ms |
94456 KB |
Output is correct |
64 |
Correct |
838 ms |
94468 KB |
Output is correct |
65 |
Incorrect |
854 ms |
94456 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
3 ms |
640 KB |
Output is correct |
3 |
Correct |
3 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
316 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
640 KB |
Output is correct |
17 |
Correct |
3 ms |
640 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Correct |
3 ms |
640 KB |
Output is correct |
20 |
Correct |
3 ms |
640 KB |
Output is correct |
21 |
Correct |
3 ms |
640 KB |
Output is correct |
22 |
Correct |
4 ms |
640 KB |
Output is correct |
23 |
Correct |
4 ms |
640 KB |
Output is correct |
24 |
Correct |
3 ms |
640 KB |
Output is correct |
25 |
Correct |
3 ms |
640 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
2 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
384 KB |
Output is correct |
36 |
Correct |
3 ms |
640 KB |
Output is correct |
37 |
Correct |
3 ms |
640 KB |
Output is correct |
38 |
Correct |
3 ms |
640 KB |
Output is correct |
39 |
Correct |
3 ms |
612 KB |
Output is correct |
40 |
Correct |
3 ms |
640 KB |
Output is correct |
41 |
Correct |
3 ms |
640 KB |
Output is correct |
42 |
Correct |
3 ms |
640 KB |
Output is correct |
43 |
Correct |
3 ms |
640 KB |
Output is correct |
44 |
Correct |
3 ms |
640 KB |
Output is correct |
45 |
Correct |
3 ms |
640 KB |
Output is correct |
46 |
Correct |
3 ms |
640 KB |
Output is correct |
47 |
Correct |
3 ms |
640 KB |
Output is correct |
48 |
Correct |
836 ms |
94460 KB |
Output is correct |
49 |
Correct |
838 ms |
94456 KB |
Output is correct |
50 |
Correct |
829 ms |
94460 KB |
Output is correct |
51 |
Correct |
838 ms |
94460 KB |
Output is correct |
52 |
Correct |
878 ms |
94456 KB |
Output is correct |
53 |
Correct |
820 ms |
94452 KB |
Output is correct |
54 |
Correct |
832 ms |
94452 KB |
Output is correct |
55 |
Correct |
840 ms |
94452 KB |
Output is correct |
56 |
Correct |
861 ms |
94452 KB |
Output is correct |
57 |
Correct |
860 ms |
94452 KB |
Output is correct |
58 |
Correct |
837 ms |
94456 KB |
Output is correct |
59 |
Correct |
841 ms |
94456 KB |
Output is correct |
60 |
Correct |
822 ms |
94492 KB |
Output is correct |
61 |
Correct |
834 ms |
94464 KB |
Output is correct |
62 |
Correct |
820 ms |
94456 KB |
Output is correct |
63 |
Correct |
825 ms |
94456 KB |
Output is correct |
64 |
Correct |
812 ms |
94452 KB |
Output is correct |
65 |
Correct |
834 ms |
94456 KB |
Output is correct |
66 |
Correct |
815 ms |
94456 KB |
Output is correct |
67 |
Correct |
825 ms |
94456 KB |
Output is correct |
68 |
Correct |
822 ms |
94464 KB |
Output is correct |
69 |
Correct |
818 ms |
94456 KB |
Output is correct |
70 |
Correct |
829 ms |
94452 KB |
Output is correct |
71 |
Correct |
845 ms |
94456 KB |
Output is correct |
72 |
Correct |
822 ms |
94328 KB |
Output is correct |
73 |
Correct |
850 ms |
94456 KB |
Output is correct |
74 |
Correct |
833 ms |
94460 KB |
Output is correct |
75 |
Correct |
834 ms |
94456 KB |
Output is correct |
76 |
Correct |
827 ms |
94460 KB |
Output is correct |
77 |
Correct |
830 ms |
94456 KB |
Output is correct |
78 |
Correct |
858 ms |
94456 KB |
Output is correct |
79 |
Correct |
838 ms |
94468 KB |
Output is correct |
80 |
Incorrect |
854 ms |
94456 KB |
Output isn't correct |
81 |
Halted |
0 ms |
0 KB |
- |