#define taskname "test"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 2005;
struct segment_tree
{
lli total[maxn * 4];
lli max_pref[maxn * 4], max_suff[maxn * 4], max_sub[maxn * 4];
void update(int x, int l, int r, int p, int k)
{
if(l == r)
{
total[x] = k;
max_sub[x] = max_pref[x] = max_suff[x] = max(0, k);
return;
}
int mid = (l + r) / 2;
if(p <= mid) update(x * 2, l, mid, p, k);
else update(x * 2 + 1, mid + 1, r, p, k);
total[x] = total[x * 2] + total[x * 2 + 1];
max_pref[x] = max(max_pref[x * 2], total[x * 2] + max_pref[x * 2 + 1]);
max_suff[x] = max(max_suff[x * 2 + 1], total[x * 2 + 1] + max_suff[x * 2]);
max_sub[x] = max(max(max_sub[x * 2], max_sub[x * 2 + 1]),
max_suff[x * 2] + max_pref[x * 2 + 1]);
}
lli get_max_sub()
{
return max_sub[1];
}
} tree;
struct point
{
int x, y;
point() {}
point(int _x, int _y) : x(_x), y(_y) {}
bool operator <(const point&other) const
{
if(y == other.y) return x < other.x;
return y > other.y;
}
};
struct frac
{
int a, b;
frac() {}
frac(int _a, int _b)
{
a = _a;
b = _b;
}
bool operator <(const frac&other) const
{
return a * 1LL * other.b < b * 1LL * other.a;
}
bool operator ==(const frac&other) const
{
return a * 1LL * other.b == b * 1LL * other.a;
}
};
int n;
pair<point, int> a[maxn];
int pos[maxn];
vector<pair<frac, pii>> events;
void read_input()
{
cin >> n;
for(int i = 1; i <= n; ++i)
{
int x, y, w;
cin >> x >> y >> w;
a[i] = make_pair(point(x, y), w);
}
}
void init()
{
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; ++i)
{
tree.update(1, 1, n, i, a[i].se);
pos[i] = i;
}
for(int i = 1; i <= n; ++i)
for(int j = i + 1; j <= n; ++j)
if(a[i].fi.y != a[j].fi.y)
{
int dx = a[j].fi.x - a[i].fi.x;
int dy = a[i].fi.y - a[j].fi.y;
events.push_back(make_pair(frac(dx, dy), pii(i, j)));
}
sort(events.begin(), events.end());
}
void solve()
{
lli ans = tree.get_max_sub();
for(int i = 0; i < sz(events); )
{
int j = i + 1;
while(j < sz(events) && events[i].fi == events[j].fi)
++j;
for(; i < j; ++i)
{
int p = events[i].se.fi, q = events[i].se.se;
tree.update(1, 1, n, pos[p], a[q].se);
tree.update(1, 1, n, pos[q], a[p].se);
swap(pos[p], pos[q]);
}
ans = max(ans, tree.get_max_sub());
}
cout << ans << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read_input();
init();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
620 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
620 KB |
Output is correct |
24 |
Correct |
2 ms |
664 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
2 ms |
620 KB |
Output is correct |
27 |
Correct |
2 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
2 ms |
620 KB |
Output is correct |
30 |
Correct |
2 ms |
620 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
620 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
620 KB |
Output is correct |
24 |
Correct |
2 ms |
664 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
2 ms |
620 KB |
Output is correct |
27 |
Correct |
2 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
2 ms |
620 KB |
Output is correct |
30 |
Correct |
2 ms |
620 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
2 ms |
620 KB |
Output is correct |
33 |
Correct |
835 ms |
33620 KB |
Output is correct |
34 |
Correct |
831 ms |
33624 KB |
Output is correct |
35 |
Correct |
808 ms |
33612 KB |
Output is correct |
36 |
Correct |
821 ms |
33612 KB |
Output is correct |
37 |
Correct |
826 ms |
33612 KB |
Output is correct |
38 |
Correct |
826 ms |
33624 KB |
Output is correct |
39 |
Correct |
812 ms |
33612 KB |
Output is correct |
40 |
Correct |
819 ms |
33624 KB |
Output is correct |
41 |
Correct |
817 ms |
33624 KB |
Output is correct |
42 |
Correct |
825 ms |
33612 KB |
Output is correct |
43 |
Correct |
809 ms |
33624 KB |
Output is correct |
44 |
Correct |
815 ms |
33792 KB |
Output is correct |
45 |
Correct |
801 ms |
33612 KB |
Output is correct |
46 |
Correct |
810 ms |
33740 KB |
Output is correct |
47 |
Correct |
803 ms |
33612 KB |
Output is correct |
48 |
Correct |
815 ms |
33624 KB |
Output is correct |
49 |
Correct |
809 ms |
33620 KB |
Output is correct |
50 |
Correct |
816 ms |
33612 KB |
Output is correct |
51 |
Correct |
809 ms |
33624 KB |
Output is correct |
52 |
Correct |
815 ms |
33624 KB |
Output is correct |
53 |
Correct |
808 ms |
33620 KB |
Output is correct |
54 |
Correct |
821 ms |
33624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
620 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
620 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
3 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
620 KB |
Output is correct |
24 |
Correct |
2 ms |
664 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
2 ms |
620 KB |
Output is correct |
27 |
Correct |
2 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
2 ms |
620 KB |
Output is correct |
30 |
Correct |
2 ms |
620 KB |
Output is correct |
31 |
Correct |
2 ms |
620 KB |
Output is correct |
32 |
Correct |
2 ms |
620 KB |
Output is correct |
33 |
Correct |
835 ms |
33620 KB |
Output is correct |
34 |
Correct |
831 ms |
33624 KB |
Output is correct |
35 |
Correct |
808 ms |
33612 KB |
Output is correct |
36 |
Correct |
821 ms |
33612 KB |
Output is correct |
37 |
Correct |
826 ms |
33612 KB |
Output is correct |
38 |
Correct |
826 ms |
33624 KB |
Output is correct |
39 |
Correct |
812 ms |
33612 KB |
Output is correct |
40 |
Correct |
819 ms |
33624 KB |
Output is correct |
41 |
Correct |
817 ms |
33624 KB |
Output is correct |
42 |
Correct |
825 ms |
33612 KB |
Output is correct |
43 |
Correct |
809 ms |
33624 KB |
Output is correct |
44 |
Correct |
815 ms |
33792 KB |
Output is correct |
45 |
Correct |
801 ms |
33612 KB |
Output is correct |
46 |
Correct |
810 ms |
33740 KB |
Output is correct |
47 |
Correct |
803 ms |
33612 KB |
Output is correct |
48 |
Correct |
815 ms |
33624 KB |
Output is correct |
49 |
Correct |
809 ms |
33620 KB |
Output is correct |
50 |
Correct |
816 ms |
33612 KB |
Output is correct |
51 |
Correct |
809 ms |
33624 KB |
Output is correct |
52 |
Correct |
815 ms |
33624 KB |
Output is correct |
53 |
Correct |
808 ms |
33620 KB |
Output is correct |
54 |
Correct |
821 ms |
33624 KB |
Output is correct |
55 |
Correct |
815 ms |
33612 KB |
Output is correct |
56 |
Correct |
824 ms |
33620 KB |
Output is correct |
57 |
Correct |
828 ms |
33624 KB |
Output is correct |
58 |
Correct |
838 ms |
33624 KB |
Output is correct |
59 |
Correct |
827 ms |
33612 KB |
Output is correct |
60 |
Correct |
838 ms |
33596 KB |
Output is correct |
61 |
Correct |
821 ms |
33612 KB |
Output is correct |
62 |
Correct |
829 ms |
33612 KB |
Output is correct |
63 |
Correct |
825 ms |
33596 KB |
Output is correct |
64 |
Correct |
814 ms |
33612 KB |
Output is correct |
65 |
Correct |
818 ms |
33620 KB |
Output is correct |
66 |
Correct |
847 ms |
33620 KB |
Output is correct |
67 |
Correct |
816 ms |
33624 KB |
Output is correct |
68 |
Correct |
825 ms |
33612 KB |
Output is correct |
69 |
Correct |
817 ms |
33624 KB |
Output is correct |
70 |
Correct |
823 ms |
33624 KB |
Output is correct |
71 |
Correct |
831 ms |
33620 KB |
Output is correct |
72 |
Correct |
820 ms |
33612 KB |
Output is correct |
73 |
Correct |
824 ms |
33624 KB |
Output is correct |
74 |
Correct |
840 ms |
33624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
2 ms |
620 KB |
Output is correct |
19 |
Correct |
2 ms |
620 KB |
Output is correct |
20 |
Correct |
2 ms |
620 KB |
Output is correct |
21 |
Correct |
2 ms |
620 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
2 ms |
620 KB |
Output is correct |
24 |
Correct |
3 ms |
620 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
2 ms |
620 KB |
Output is correct |
37 |
Correct |
2 ms |
620 KB |
Output is correct |
38 |
Correct |
2 ms |
620 KB |
Output is correct |
39 |
Correct |
2 ms |
664 KB |
Output is correct |
40 |
Correct |
2 ms |
620 KB |
Output is correct |
41 |
Correct |
2 ms |
620 KB |
Output is correct |
42 |
Correct |
2 ms |
620 KB |
Output is correct |
43 |
Correct |
2 ms |
620 KB |
Output is correct |
44 |
Correct |
2 ms |
620 KB |
Output is correct |
45 |
Correct |
2 ms |
620 KB |
Output is correct |
46 |
Correct |
2 ms |
620 KB |
Output is correct |
47 |
Correct |
2 ms |
620 KB |
Output is correct |
48 |
Correct |
835 ms |
33620 KB |
Output is correct |
49 |
Correct |
831 ms |
33624 KB |
Output is correct |
50 |
Correct |
808 ms |
33612 KB |
Output is correct |
51 |
Correct |
821 ms |
33612 KB |
Output is correct |
52 |
Correct |
826 ms |
33612 KB |
Output is correct |
53 |
Correct |
826 ms |
33624 KB |
Output is correct |
54 |
Correct |
812 ms |
33612 KB |
Output is correct |
55 |
Correct |
819 ms |
33624 KB |
Output is correct |
56 |
Correct |
817 ms |
33624 KB |
Output is correct |
57 |
Correct |
825 ms |
33612 KB |
Output is correct |
58 |
Correct |
809 ms |
33624 KB |
Output is correct |
59 |
Correct |
815 ms |
33792 KB |
Output is correct |
60 |
Correct |
801 ms |
33612 KB |
Output is correct |
61 |
Correct |
810 ms |
33740 KB |
Output is correct |
62 |
Correct |
803 ms |
33612 KB |
Output is correct |
63 |
Correct |
815 ms |
33624 KB |
Output is correct |
64 |
Correct |
809 ms |
33620 KB |
Output is correct |
65 |
Correct |
816 ms |
33612 KB |
Output is correct |
66 |
Correct |
809 ms |
33624 KB |
Output is correct |
67 |
Correct |
815 ms |
33624 KB |
Output is correct |
68 |
Correct |
808 ms |
33620 KB |
Output is correct |
69 |
Correct |
821 ms |
33624 KB |
Output is correct |
70 |
Correct |
815 ms |
33612 KB |
Output is correct |
71 |
Correct |
824 ms |
33620 KB |
Output is correct |
72 |
Correct |
828 ms |
33624 KB |
Output is correct |
73 |
Correct |
838 ms |
33624 KB |
Output is correct |
74 |
Correct |
827 ms |
33612 KB |
Output is correct |
75 |
Correct |
838 ms |
33596 KB |
Output is correct |
76 |
Correct |
821 ms |
33612 KB |
Output is correct |
77 |
Correct |
829 ms |
33612 KB |
Output is correct |
78 |
Correct |
825 ms |
33596 KB |
Output is correct |
79 |
Correct |
814 ms |
33612 KB |
Output is correct |
80 |
Correct |
818 ms |
33620 KB |
Output is correct |
81 |
Correct |
847 ms |
33620 KB |
Output is correct |
82 |
Correct |
816 ms |
33624 KB |
Output is correct |
83 |
Correct |
825 ms |
33612 KB |
Output is correct |
84 |
Correct |
817 ms |
33624 KB |
Output is correct |
85 |
Correct |
823 ms |
33624 KB |
Output is correct |
86 |
Correct |
831 ms |
33620 KB |
Output is correct |
87 |
Correct |
820 ms |
33612 KB |
Output is correct |
88 |
Correct |
824 ms |
33624 KB |
Output is correct |
89 |
Correct |
840 ms |
33624 KB |
Output is correct |
90 |
Correct |
829 ms |
33624 KB |
Output is correct |
91 |
Correct |
817 ms |
33608 KB |
Output is correct |
92 |
Correct |
822 ms |
33632 KB |
Output is correct |
93 |
Correct |
815 ms |
33612 KB |
Output is correct |
94 |
Correct |
819 ms |
33624 KB |
Output is correct |
95 |
Correct |
824 ms |
33612 KB |
Output is correct |
96 |
Correct |
822 ms |
33596 KB |
Output is correct |
97 |
Correct |
819 ms |
33560 KB |
Output is correct |
98 |
Correct |
815 ms |
33612 KB |
Output is correct |
99 |
Correct |
816 ms |
33624 KB |
Output is correct |
100 |
Correct |
748 ms |
33624 KB |
Output is correct |
101 |
Correct |
757 ms |
33752 KB |
Output is correct |
102 |
Correct |
720 ms |
33624 KB |
Output is correct |
103 |
Correct |
717 ms |
33612 KB |
Output is correct |
104 |
Correct |
722 ms |
33612 KB |
Output is correct |
105 |
Correct |
764 ms |
33612 KB |
Output is correct |
106 |
Correct |
768 ms |
33612 KB |
Output is correct |
107 |
Correct |
770 ms |
33624 KB |
Output is correct |
108 |
Correct |
755 ms |
33624 KB |
Output is correct |
109 |
Correct |
754 ms |
33624 KB |
Output is correct |
110 |
Correct |
743 ms |
33496 KB |
Output is correct |
111 |
Correct |
746 ms |
33484 KB |
Output is correct |
112 |
Correct |
748 ms |
33596 KB |
Output is correct |
113 |
Correct |
747 ms |
33484 KB |
Output is correct |
114 |
Correct |
747 ms |
33484 KB |
Output is correct |
115 |
Correct |
744 ms |
33612 KB |
Output is correct |
116 |
Correct |
746 ms |
33624 KB |
Output is correct |
117 |
Correct |
745 ms |
33484 KB |
Output is correct |
118 |
Correct |
738 ms |
33496 KB |
Output is correct |
119 |
Correct |
742 ms |
33632 KB |
Output is correct |
120 |
Correct |
1 ms |
364 KB |
Output is correct |
121 |
Correct |
1 ms |
364 KB |
Output is correct |
122 |
Correct |
850 ms |
33620 KB |
Output is correct |
123 |
Correct |
836 ms |
33624 KB |
Output is correct |
124 |
Correct |
845 ms |
33612 KB |
Output is correct |
125 |
Correct |
822 ms |
33612 KB |
Output is correct |
126 |
Correct |
816 ms |
33612 KB |
Output is correct |
127 |
Correct |
827 ms |
33624 KB |
Output is correct |
128 |
Correct |
817 ms |
33596 KB |
Output is correct |
129 |
Correct |
819 ms |
33624 KB |
Output is correct |
130 |
Correct |
832 ms |
33612 KB |
Output is correct |
131 |
Correct |
814 ms |
33624 KB |
Output is correct |
132 |
Correct |
816 ms |
33596 KB |
Output is correct |
133 |
Correct |
814 ms |
33624 KB |
Output is correct |