#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];
// cout << u << " " << v << endl;
// swap(p[l[u]], p[l[v]]);
// for(int j=0; j<n; ++j)
// cout << p[j] << " ";
// cout << endl;
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 << "ta " << st[1][3] << endl;
}
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]))
~~~~~~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
768 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 |
640 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 |
4 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 |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
768 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 |
640 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 |
4 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 |
859 ms |
94452 KB |
Output is correct |
34 |
Correct |
845 ms |
94456 KB |
Output is correct |
35 |
Correct |
838 ms |
94456 KB |
Output is correct |
36 |
Correct |
862 ms |
94452 KB |
Output is correct |
37 |
Correct |
857 ms |
94560 KB |
Output is correct |
38 |
Correct |
868 ms |
94456 KB |
Output is correct |
39 |
Correct |
860 ms |
94460 KB |
Output is correct |
40 |
Correct |
908 ms |
94452 KB |
Output is correct |
41 |
Correct |
875 ms |
94456 KB |
Output is correct |
42 |
Correct |
830 ms |
94584 KB |
Output is correct |
43 |
Correct |
817 ms |
94456 KB |
Output is correct |
44 |
Correct |
879 ms |
94328 KB |
Output is correct |
45 |
Correct |
855 ms |
94344 KB |
Output is correct |
46 |
Correct |
861 ms |
94460 KB |
Output is correct |
47 |
Correct |
834 ms |
94456 KB |
Output is correct |
48 |
Correct |
821 ms |
94456 KB |
Output is correct |
49 |
Correct |
816 ms |
94456 KB |
Output is correct |
50 |
Correct |
859 ms |
94460 KB |
Output is correct |
51 |
Correct |
833 ms |
94456 KB |
Output is correct |
52 |
Correct |
833 ms |
94584 KB |
Output is correct |
53 |
Correct |
897 ms |
94456 KB |
Output is correct |
54 |
Correct |
853 ms |
94452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
768 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 |
640 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 |
4 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 |
859 ms |
94452 KB |
Output is correct |
34 |
Correct |
845 ms |
94456 KB |
Output is correct |
35 |
Correct |
838 ms |
94456 KB |
Output is correct |
36 |
Correct |
862 ms |
94452 KB |
Output is correct |
37 |
Correct |
857 ms |
94560 KB |
Output is correct |
38 |
Correct |
868 ms |
94456 KB |
Output is correct |
39 |
Correct |
860 ms |
94460 KB |
Output is correct |
40 |
Correct |
908 ms |
94452 KB |
Output is correct |
41 |
Correct |
875 ms |
94456 KB |
Output is correct |
42 |
Correct |
830 ms |
94584 KB |
Output is correct |
43 |
Correct |
817 ms |
94456 KB |
Output is correct |
44 |
Correct |
879 ms |
94328 KB |
Output is correct |
45 |
Correct |
855 ms |
94344 KB |
Output is correct |
46 |
Correct |
861 ms |
94460 KB |
Output is correct |
47 |
Correct |
834 ms |
94456 KB |
Output is correct |
48 |
Correct |
821 ms |
94456 KB |
Output is correct |
49 |
Correct |
816 ms |
94456 KB |
Output is correct |
50 |
Correct |
859 ms |
94460 KB |
Output is correct |
51 |
Correct |
833 ms |
94456 KB |
Output is correct |
52 |
Correct |
833 ms |
94584 KB |
Output is correct |
53 |
Correct |
897 ms |
94456 KB |
Output is correct |
54 |
Correct |
853 ms |
94452 KB |
Output is correct |
55 |
Correct |
871 ms |
94464 KB |
Output is correct |
56 |
Correct |
835 ms |
94456 KB |
Output is correct |
57 |
Correct |
865 ms |
94456 KB |
Output is correct |
58 |
Correct |
852 ms |
94452 KB |
Output is correct |
59 |
Correct |
867 ms |
94496 KB |
Output is correct |
60 |
Correct |
843 ms |
94452 KB |
Output is correct |
61 |
Correct |
911 ms |
94456 KB |
Output is correct |
62 |
Correct |
847 ms |
94452 KB |
Output is correct |
63 |
Correct |
841 ms |
94460 KB |
Output is correct |
64 |
Correct |
839 ms |
94456 KB |
Output is correct |
65 |
Correct |
858 ms |
94460 KB |
Output is correct |
66 |
Correct |
853 ms |
94452 KB |
Output is correct |
67 |
Correct |
861 ms |
94456 KB |
Output is correct |
68 |
Correct |
825 ms |
94456 KB |
Output is correct |
69 |
Correct |
834 ms |
94496 KB |
Output is correct |
70 |
Correct |
842 ms |
94460 KB |
Output is correct |
71 |
Correct |
820 ms |
94460 KB |
Output is correct |
72 |
Correct |
827 ms |
94576 KB |
Output is correct |
73 |
Correct |
825 ms |
94456 KB |
Output is correct |
74 |
Correct |
852 ms |
94452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
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 |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
3 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 |
768 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 |
640 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 |
4 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 |
859 ms |
94452 KB |
Output is correct |
49 |
Correct |
845 ms |
94456 KB |
Output is correct |
50 |
Correct |
838 ms |
94456 KB |
Output is correct |
51 |
Correct |
862 ms |
94452 KB |
Output is correct |
52 |
Correct |
857 ms |
94560 KB |
Output is correct |
53 |
Correct |
868 ms |
94456 KB |
Output is correct |
54 |
Correct |
860 ms |
94460 KB |
Output is correct |
55 |
Correct |
908 ms |
94452 KB |
Output is correct |
56 |
Correct |
875 ms |
94456 KB |
Output is correct |
57 |
Correct |
830 ms |
94584 KB |
Output is correct |
58 |
Correct |
817 ms |
94456 KB |
Output is correct |
59 |
Correct |
879 ms |
94328 KB |
Output is correct |
60 |
Correct |
855 ms |
94344 KB |
Output is correct |
61 |
Correct |
861 ms |
94460 KB |
Output is correct |
62 |
Correct |
834 ms |
94456 KB |
Output is correct |
63 |
Correct |
821 ms |
94456 KB |
Output is correct |
64 |
Correct |
816 ms |
94456 KB |
Output is correct |
65 |
Correct |
859 ms |
94460 KB |
Output is correct |
66 |
Correct |
833 ms |
94456 KB |
Output is correct |
67 |
Correct |
833 ms |
94584 KB |
Output is correct |
68 |
Correct |
897 ms |
94456 KB |
Output is correct |
69 |
Correct |
853 ms |
94452 KB |
Output is correct |
70 |
Correct |
871 ms |
94464 KB |
Output is correct |
71 |
Correct |
835 ms |
94456 KB |
Output is correct |
72 |
Correct |
865 ms |
94456 KB |
Output is correct |
73 |
Correct |
852 ms |
94452 KB |
Output is correct |
74 |
Correct |
867 ms |
94496 KB |
Output is correct |
75 |
Correct |
843 ms |
94452 KB |
Output is correct |
76 |
Correct |
911 ms |
94456 KB |
Output is correct |
77 |
Correct |
847 ms |
94452 KB |
Output is correct |
78 |
Correct |
841 ms |
94460 KB |
Output is correct |
79 |
Correct |
839 ms |
94456 KB |
Output is correct |
80 |
Correct |
858 ms |
94460 KB |
Output is correct |
81 |
Correct |
853 ms |
94452 KB |
Output is correct |
82 |
Correct |
861 ms |
94456 KB |
Output is correct |
83 |
Correct |
825 ms |
94456 KB |
Output is correct |
84 |
Correct |
834 ms |
94496 KB |
Output is correct |
85 |
Correct |
842 ms |
94460 KB |
Output is correct |
86 |
Correct |
820 ms |
94460 KB |
Output is correct |
87 |
Correct |
827 ms |
94576 KB |
Output is correct |
88 |
Correct |
825 ms |
94456 KB |
Output is correct |
89 |
Correct |
852 ms |
94452 KB |
Output is correct |
90 |
Correct |
837 ms |
94456 KB |
Output is correct |
91 |
Correct |
833 ms |
94460 KB |
Output is correct |
92 |
Correct |
830 ms |
94452 KB |
Output is correct |
93 |
Correct |
845 ms |
94456 KB |
Output is correct |
94 |
Correct |
858 ms |
94456 KB |
Output is correct |
95 |
Correct |
862 ms |
94460 KB |
Output is correct |
96 |
Correct |
855 ms |
94456 KB |
Output is correct |
97 |
Correct |
845 ms |
94456 KB |
Output is correct |
98 |
Correct |
831 ms |
94456 KB |
Output is correct |
99 |
Correct |
880 ms |
94460 KB |
Output is correct |
100 |
Correct |
825 ms |
94452 KB |
Output is correct |
101 |
Correct |
804 ms |
94456 KB |
Output is correct |
102 |
Correct |
827 ms |
94452 KB |
Output is correct |
103 |
Correct |
807 ms |
94464 KB |
Output is correct |
104 |
Correct |
818 ms |
94452 KB |
Output is correct |
105 |
Correct |
823 ms |
94456 KB |
Output is correct |
106 |
Correct |
822 ms |
94452 KB |
Output is correct |
107 |
Correct |
827 ms |
94456 KB |
Output is correct |
108 |
Correct |
817 ms |
94456 KB |
Output is correct |
109 |
Correct |
823 ms |
94456 KB |
Output is correct |
110 |
Correct |
826 ms |
94456 KB |
Output is correct |
111 |
Correct |
807 ms |
94460 KB |
Output is correct |
112 |
Correct |
813 ms |
94456 KB |
Output is correct |
113 |
Correct |
793 ms |
94412 KB |
Output is correct |
114 |
Correct |
788 ms |
94460 KB |
Output is correct |
115 |
Correct |
798 ms |
94456 KB |
Output is correct |
116 |
Correct |
793 ms |
94556 KB |
Output is correct |
117 |
Correct |
800 ms |
94464 KB |
Output is correct |
118 |
Correct |
790 ms |
94460 KB |
Output is correct |
119 |
Correct |
798 ms |
94456 KB |
Output is correct |
120 |
Correct |
2 ms |
384 KB |
Output is correct |
121 |
Correct |
2 ms |
384 KB |
Output is correct |
122 |
Correct |
838 ms |
94468 KB |
Output is correct |
123 |
Correct |
826 ms |
94504 KB |
Output is correct |
124 |
Correct |
832 ms |
94576 KB |
Output is correct |
125 |
Correct |
816 ms |
94364 KB |
Output is correct |
126 |
Correct |
837 ms |
94452 KB |
Output is correct |
127 |
Correct |
822 ms |
94464 KB |
Output is correct |
128 |
Correct |
855 ms |
94536 KB |
Output is correct |
129 |
Correct |
828 ms |
94460 KB |
Output is correct |
130 |
Correct |
849 ms |
94456 KB |
Output is correct |
131 |
Correct |
836 ms |
94476 KB |
Output is correct |
132 |
Correct |
813 ms |
94452 KB |
Output is correct |
133 |
Correct |
816 ms |
94460 KB |
Output is correct |