#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];
int gcd(int x, int y) {
if (x > y) swap(x, y);
if (x == 0) return y;
return gcd(y%x, x);
}
struct Rel {
int p, q;
Rel(int p, int q) : p(p), q(q) {
if (q < 0) p = -p, q = -q;
//int g = gcd(abs(p), abs(q)); p/=g, q/=g;
}
bool operator<(const Rel& b) const {
return p*b.q < b.p*q;
}
};
map<Rel, vector<P> > lines;
int pos[2000];
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]));
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[r].pb(P(i, j));
}
long long m = seg[0].m;
for (auto &e : lines) {
//rep(i, N)cout<<seg[i+MAX_N-1].s<<",";cout<<": "<<seg[0].m<<"\n";
Rel a = e._1;
map<long long, vector<P>> bs;
auto add = [&](int i) {
int x = X[i], y = Y[i];
bs[1LL*y*a.q-1LL*x*a.p].pb(P(pos[i], i));
};
for (P p : e._2) add(p._1), add(p._2);
for (auto &p : bs) {
vector<P> &ps = p._2;
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]));
}
}
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:103:7: note: in expansion of macro 'rep'
rep(i, ps.size()/2) {
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
3 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Incorrect |
6 ms |
1080 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |