#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct Node {
long long s, l, r, m;
Node(long long s, long long l, long long r, long long m) : s(s), l(l), r(r), m(m) {}
Node(long long w) : Node(w, max(w, 0LL), max(w, 0LL), max(w, 0LL)) {}
Node() : Node(0) {}
};
Node op(const Node &a, const Node &b) {
return Node(
a.s + b.s,
max(a.l, a.s + b.l),
max(b.r, b.s + a.r),
max(max(a.m, b.m), a.r + b.l)
);
}
#define MAX_N (1<<11)
Node seg[MAX_N*2-1];
void update(int k, Node x) {
k += MAX_N-1;
seg[k] = x;
while (k > 0) {
k = (k-1)/2;
seg[k] = op(seg[k*2+1], seg[k*2+2]);
}
}
int N;
int X[2000], Y[2000], W[2000];
struct Rel {
int p, q;
Rel(int p, int q) : p(p), q(q) {
if (q < 0) p = -p, q = -q;
}
bool operator<(const Rel& b) const { return 1LL*p*b.q < 1LL*b.p*q; }
bool operator==(const Rel& b) const { return 1LL*p*b.q == 1LL*b.p*q; }
};
int pos[2000];
vector<P> G[1999000];
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N;
vector<P2> ps;
rep(i, N) {
int x, y, w;
cin >> x >> y >> w;
ps.pb(P2(P(x, -y), w));
}
sort(all(ps));
rep(i, N) X[i] = ps[i]._1._1, Y[i] = -ps[i]._1._2, W[i] = ps[i]._2, pos[i] = i, update(i, Node(W[i]));
vector<pair<Rel, P>> lines;
rep(i, N) rep(j, i) {
Rel r = Rel(-1, 0);
if (X[i] != X[j]) r = Rel(Y[i]-Y[j], X[i]-X[j]);
lines.pb(make_pair(r, P(i, j)));
}
sort(all(lines));
long long m = seg[0].m;
vector<long long> bs;
Rel a = lines[0]._1;
vector<int> ln;
rep(e, lines.size()) {
if (!(a == lines[e]._1)) a = lines[e]._1;
P p = lines[e]._2;
bs.pb(1LL*Y[p._1]*a.q-1LL*X[p._1]*a.p);
ln.pb(p._1);
ln.pb(p._2);
if (e+1 >= lines.size() || !(a == lines[e+1]._1)) {
sort(all(bs)); uniq(bs);
for (int p : ln) {
int k = index(bs, 1LL*Y[p]*a.q-1LL*X[p]*a.p);
G[k].pb(P(pos[p], p));
}
rep(i, bs.size()) {
vector<P> &ps = G[i];
sort(all(ps)); uniq(ps);
rep(i, ps.size()/2) {
int a = ps[i]._2, b = ps[(int)ps.size()-1-i]._2;
swap(pos[a], pos[b]);
update(pos[a], Node(W[a]));
update(pos[b], Node(W[b]));
}
}
rep(i, bs.size()) G[i].clear();
bs.clear();
ln.clear();
m = max(m, seg[0].m);
}
}
cout << m << "\n";
return 0;
}
Compilation message
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
bulldozer.cpp:89:3: note: in expansion of macro 'rep'
rep(e, lines.size()) {
^~~
bulldozer.cpp:96:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (e+1 >= lines.size() || !(a == lines[e+1]._1)) {
~~~~^~~~~~~~~~~~~~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
bulldozer.cpp:102:7: note: in expansion of macro 'rep'
rep(i, bs.size()) {
^~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
bulldozer.cpp:105:9: note: in expansion of macro 'rep'
rep(i, ps.size()/2) {
^~~
bulldozer.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
bulldozer.cpp:112:7: note: in expansion of macro 'rep'
rep(i, bs.size()) G[i].clear();
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
47992 KB |
Output is correct |
2 |
Correct |
44 ms |
47764 KB |
Output is correct |
3 |
Correct |
47 ms |
47772 KB |
Output is correct |
4 |
Correct |
46 ms |
47800 KB |
Output is correct |
5 |
Correct |
47 ms |
47864 KB |
Output is correct |
6 |
Correct |
46 ms |
47864 KB |
Output is correct |
7 |
Correct |
45 ms |
47836 KB |
Output is correct |
8 |
Correct |
45 ms |
47864 KB |
Output is correct |
9 |
Correct |
46 ms |
47836 KB |
Output is correct |
10 |
Correct |
47 ms |
47836 KB |
Output is correct |
11 |
Runtime error |
94 ms |
94712 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47608 KB |
Output is correct |
3 |
Correct |
44 ms |
47612 KB |
Output is correct |
4 |
Correct |
45 ms |
47608 KB |
Output is correct |
5 |
Correct |
45 ms |
47608 KB |
Output is correct |
6 |
Correct |
45 ms |
47660 KB |
Output is correct |
7 |
Correct |
44 ms |
47608 KB |
Output is correct |
8 |
Correct |
44 ms |
47736 KB |
Output is correct |
9 |
Correct |
46 ms |
47608 KB |
Output is correct |
10 |
Correct |
44 ms |
47640 KB |
Output is correct |
11 |
Runtime error |
92 ms |
94644 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47608 KB |
Output is correct |
3 |
Correct |
44 ms |
47612 KB |
Output is correct |
4 |
Correct |
45 ms |
47608 KB |
Output is correct |
5 |
Correct |
45 ms |
47608 KB |
Output is correct |
6 |
Correct |
45 ms |
47660 KB |
Output is correct |
7 |
Correct |
44 ms |
47608 KB |
Output is correct |
8 |
Correct |
44 ms |
47736 KB |
Output is correct |
9 |
Correct |
46 ms |
47608 KB |
Output is correct |
10 |
Correct |
44 ms |
47640 KB |
Output is correct |
11 |
Runtime error |
92 ms |
94644 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
47736 KB |
Output is correct |
2 |
Correct |
45 ms |
47608 KB |
Output is correct |
3 |
Correct |
44 ms |
47612 KB |
Output is correct |
4 |
Correct |
45 ms |
47608 KB |
Output is correct |
5 |
Correct |
45 ms |
47608 KB |
Output is correct |
6 |
Correct |
45 ms |
47660 KB |
Output is correct |
7 |
Correct |
44 ms |
47608 KB |
Output is correct |
8 |
Correct |
44 ms |
47736 KB |
Output is correct |
9 |
Correct |
46 ms |
47608 KB |
Output is correct |
10 |
Correct |
44 ms |
47640 KB |
Output is correct |
11 |
Runtime error |
92 ms |
94644 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
47992 KB |
Output is correct |
2 |
Correct |
44 ms |
47764 KB |
Output is correct |
3 |
Correct |
47 ms |
47772 KB |
Output is correct |
4 |
Correct |
46 ms |
47800 KB |
Output is correct |
5 |
Correct |
47 ms |
47864 KB |
Output is correct |
6 |
Correct |
46 ms |
47864 KB |
Output is correct |
7 |
Correct |
45 ms |
47836 KB |
Output is correct |
8 |
Correct |
45 ms |
47864 KB |
Output is correct |
9 |
Correct |
46 ms |
47836 KB |
Output is correct |
10 |
Correct |
47 ms |
47836 KB |
Output is correct |
11 |
Runtime error |
94 ms |
94712 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |