#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
struct ST{
struct node{
ll pr, sf, mx, s;
};
vector<node> t;
int n;
ST(int ns){
n = ns;
t.resize(4 * n);
}
void upd(int v, int tl, int tr, int& p, int& x){
if (tl == tr){
t[v].s = x;
t[v].pr = t[v].sf = t[v].mx = max(0, x);
return;
}
int tm = (tl + tr) / 2, vv = 2 * v;
if (p <= tm){
upd(vv, tl, tm, p, x);
}
else {
upd(vv + 1, tm + 1, tr, p, x);
}
t[v].s = t[vv].s + t[vv + 1].s;
t[v].mx = max({t[vv].mx, t[vv + 1].mx, t[vv].sf + t[vv + 1].pr});
t[v].pr = max(t[vv].pr, t[vv].s + t[vv + 1].pr);
t[v].sf = max(t[vv + 1].sf, t[vv + 1].s + t[vv].sf);
}
void upd(int p, int x){
upd(1, 1, n, p, x);
}
ll get(){
return t[1].mx;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> x(n + 1), y(n + 1), a(n + 1), f = {0};
for (int i = 1; i <= n; i++){
cin>>x[i]>>y[i]>>a[i];
f.pb(i);
}
auto cmp = [&](int i, int j){
return x[i] < x[j];
};
sort(f.begin() + 1, f.end(), cmp);
vector<int> p(n + 1);
for (int i = 1; i <= n; i++){
p[f[i]] = i;
}
ST T(n);
for (int i = 1; i <= n; i++){
T.upd(p[i], a[i]);
}
ll out = T.get();
vector<pair<pii, pii>> all;
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
if (x[f[i]] != x[f[j]]){
all.pb({{y[f[j]] - y[f[i]], x[f[j]] - x[f[i]]}, {f[i], f[j]}});
}
}
}
auto cmp1 = [&](pair<pii, pii> a, pair<pii, pii> b){
auto [u1, v1] = a.ff;
auto [u2, v2] = b.ff;
return 1LL * u1 * v2 < 1LL * u2 * v1;
};
sort(all.begin(), all.end(), cmp1);
int i = 0;
while (i < all.size()){
int j = i;
while (j < all.size() && (1LL * all[i].ff.ff * all[j].ff.ss) == (1LL * all[i].ff.ss * all[j].ff.ff)){
auto [u, v] = all[j].ss;
assert(abs(p[u] - p[v]) == 1);
swap(p[u], p[v]);
T.upd(p[u], a[u]);
T.upd(p[v], a[v]);
j++;
}
out = max(out, T.get());
i = j;
}
cout<<out<<"\n";
}
Compilation message
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:89:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | while (i < all.size()){
| ~~^~~~~~~~~~~~
bulldozer.cpp:91:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | while (j < all.size() && (1LL * all[i].ff.ff * all[j].ff.ss) == (1LL * all[i].ff.ss * all[j].ff.ff)){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
848 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
508 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
2 ms |
592 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
2 ms |
592 KB |
Output is correct |
29 |
Correct |
2 ms |
592 KB |
Output is correct |
30 |
Correct |
2 ms |
592 KB |
Output is correct |
31 |
Correct |
2 ms |
592 KB |
Output is correct |
32 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
508 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
2 ms |
592 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
2 ms |
592 KB |
Output is correct |
29 |
Correct |
2 ms |
592 KB |
Output is correct |
30 |
Correct |
2 ms |
592 KB |
Output is correct |
31 |
Correct |
2 ms |
592 KB |
Output is correct |
32 |
Correct |
2 ms |
592 KB |
Output is correct |
33 |
Correct |
682 ms |
35764 KB |
Output is correct |
34 |
Correct |
688 ms |
35764 KB |
Output is correct |
35 |
Correct |
714 ms |
35764 KB |
Output is correct |
36 |
Correct |
690 ms |
35764 KB |
Output is correct |
37 |
Correct |
678 ms |
35764 KB |
Output is correct |
38 |
Correct |
703 ms |
35764 KB |
Output is correct |
39 |
Correct |
716 ms |
35764 KB |
Output is correct |
40 |
Correct |
704 ms |
35764 KB |
Output is correct |
41 |
Correct |
679 ms |
35776 KB |
Output is correct |
42 |
Correct |
719 ms |
35764 KB |
Output is correct |
43 |
Correct |
697 ms |
35764 KB |
Output is correct |
44 |
Correct |
687 ms |
35764 KB |
Output is correct |
45 |
Correct |
686 ms |
35764 KB |
Output is correct |
46 |
Correct |
697 ms |
35764 KB |
Output is correct |
47 |
Correct |
699 ms |
35756 KB |
Output is correct |
48 |
Correct |
719 ms |
35764 KB |
Output is correct |
49 |
Correct |
723 ms |
35764 KB |
Output is correct |
50 |
Correct |
719 ms |
35764 KB |
Output is correct |
51 |
Correct |
677 ms |
35764 KB |
Output is correct |
52 |
Correct |
693 ms |
35764 KB |
Output is correct |
53 |
Correct |
713 ms |
35764 KB |
Output is correct |
54 |
Correct |
719 ms |
35764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
3 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
508 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
2 ms |
592 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
2 ms |
592 KB |
Output is correct |
29 |
Correct |
2 ms |
592 KB |
Output is correct |
30 |
Correct |
2 ms |
592 KB |
Output is correct |
31 |
Correct |
2 ms |
592 KB |
Output is correct |
32 |
Correct |
2 ms |
592 KB |
Output is correct |
33 |
Correct |
682 ms |
35764 KB |
Output is correct |
34 |
Correct |
688 ms |
35764 KB |
Output is correct |
35 |
Correct |
714 ms |
35764 KB |
Output is correct |
36 |
Correct |
690 ms |
35764 KB |
Output is correct |
37 |
Correct |
678 ms |
35764 KB |
Output is correct |
38 |
Correct |
703 ms |
35764 KB |
Output is correct |
39 |
Correct |
716 ms |
35764 KB |
Output is correct |
40 |
Correct |
704 ms |
35764 KB |
Output is correct |
41 |
Correct |
679 ms |
35776 KB |
Output is correct |
42 |
Correct |
719 ms |
35764 KB |
Output is correct |
43 |
Correct |
697 ms |
35764 KB |
Output is correct |
44 |
Correct |
687 ms |
35764 KB |
Output is correct |
45 |
Correct |
686 ms |
35764 KB |
Output is correct |
46 |
Correct |
697 ms |
35764 KB |
Output is correct |
47 |
Correct |
699 ms |
35756 KB |
Output is correct |
48 |
Correct |
719 ms |
35764 KB |
Output is correct |
49 |
Correct |
723 ms |
35764 KB |
Output is correct |
50 |
Correct |
719 ms |
35764 KB |
Output is correct |
51 |
Correct |
677 ms |
35764 KB |
Output is correct |
52 |
Correct |
693 ms |
35764 KB |
Output is correct |
53 |
Correct |
713 ms |
35764 KB |
Output is correct |
54 |
Correct |
719 ms |
35764 KB |
Output is correct |
55 |
Correct |
717 ms |
35764 KB |
Output is correct |
56 |
Correct |
718 ms |
35764 KB |
Output is correct |
57 |
Correct |
692 ms |
35776 KB |
Output is correct |
58 |
Correct |
681 ms |
35764 KB |
Output is correct |
59 |
Correct |
695 ms |
35764 KB |
Output is correct |
60 |
Correct |
700 ms |
35832 KB |
Output is correct |
61 |
Correct |
709 ms |
35764 KB |
Output is correct |
62 |
Correct |
695 ms |
35764 KB |
Output is correct |
63 |
Correct |
698 ms |
35764 KB |
Output is correct |
64 |
Correct |
706 ms |
35764 KB |
Output is correct |
65 |
Runtime error |
259 ms |
68076 KB |
Execution killed with signal 6 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
848 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |