#include <tuple>
#include <vector>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
struct point {
long long x, y;
point() : x(0), y(0) {};
point(long long x_, long long y_) : x(x_), y(y_) {};
point operator+(const point& p) const { return point(x + p.x, y + p.y); }
point operator-(const point& p) const { return point(x - p.x, y - p.y); }
long long cross(const point& p) const { return x * p.y - y * p.x; }
};
int shougen(const point &p) {
if(p.y == 0) return p.x > 0 ? 0 : 4;
if(p.x == 0) return p.y > 0 ? 2 : 6;
if(p.y > 0) return p.x > 0 ? 1 : 3;
return p.x > 0 ? 7 : 5;
}
const long long inf = 1LL << 62;
class segtree {
private:
int sz;
vector<long long> val;
long long query(int a, int b, int k, int l, int r) {
if(a <= l && r <= b) return val[k];
if(r <= a || b <= l) return -inf;
long long lc = query(a, b, k * 2, l, (l + r) >> 1);
long long rc = query(a, b, k * 2 + 1, (l + r) >> 1, r);
return max(lc, rc);
}
public:
segtree() : sz(0), val(vector<long long>()) {};
segtree(int sz_) {
sz = 1;
while(sz < sz_) sz *= 2;
val.resize(2 * sz);
}
void update(int pos, long long x) {
pos += sz;
val[pos] = x;
while(pos > 1) {
pos >>= 1;
val[pos] = max(val[pos * 2], val[pos * 2 + 1]);
}
}
long long rangemin(int l, int r) {
return query(l, r, 1, 0, sz);
}
};
long long solve(int N, vector<int> X, vector<int> Y, vector<long long> V) {
vector<point> P(N);
for(int i = 0; i < N; ++i) P[i] = point(X[i], Y[i]);
vector<int> perm(N);
for(int i = 0; i < N; ++i) perm[i] = i;
sort(perm.begin(), perm.end(), [&](int i, int j) { return P[i].y != P[j].y ? P[i].y < P[j].y : P[i].x < P[j].x; });
vector<int> inv(N);
for(int i = 0; i < N; ++i) inv[perm[i]] = i;
vector<tuple<point, int, int> > vec;
for(int i = 0; i < N; ++i) {
for(int j = 0; j < N; ++j) {
if(i != j) vec.push_back(make_tuple(P[i] - P[j], i, j));
}
}
vector<int> vecperm(vec.size());
for(int i = 0; i < vec.size(); ++i) vecperm[i] = i;
sort(vecperm.begin(), vecperm.end(), [&](int i, int j) {
point p1 = get<0>(vec[i]), p2 = get<0>(vec[j]);
int s1 = shougen(p1), s2 = shougen(p2);
if(s1 != s2) return s1 < s2;
return p1.cross(p2) > 0;
});
vector<long long> ruiseki(N + 1);
for(int i = 0; i < N; ++i) ruiseki[i + 1] = ruiseki[i] + V[perm[i]];
segtree seg(N + 1);
for(int i = 0; i <= N; ++i) {
seg.update(i, ruiseki[i]);
}
long long ans = *max_element(V.begin(), V.end());
ans = max(ans, 0LL);
for(int i = 0; i < vec.size(); ++i) {
int pa = get<1>(vec[vecperm[i]]), pb = get<2>(vec[vecperm[i]]);
int pos = min(inv[pa], inv[pb]);
swap(inv[pa], inv[pb]);
swap(perm[pos], perm[pos + 1]);
ruiseki[pos + 1] = ruiseki[pos] + ruiseki[pos + 2] - ruiseki[pos + 1];
seg.update(pos + 1, ruiseki[pos + 1]);
long long delta = max(-min(ruiseki[pos + 1] - ruiseki[pos], ruiseki[pos + 2] - ruiseki[pos + 1]), 0LL);
long long maxi = seg.rangemin(pos + 2, N + 1);
ans = max(ans, maxi - ruiseki[pos] + delta);
}
return ans;
}
int main() {
int N;
cin >> N;
vector<int> X(N), Y(N); vector<long long> V(N);
for(int i = 0; i < N; ++i) {
cin >> X[i] >> Y[i] >> V[i];
}
long long ans = solve(N, X, Y, V);
cout << ans << endl;
return 0;
}
Compilation message
bulldozer.cpp: In function 'long long int solve(int, std::vector<int>, std::vector<int>, std::vector<long long int>)':
bulldozer.cpp:67:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec.size(); ++i) vecperm[i] = i;
~~^~~~~~~~~~~~
bulldozer.cpp:82:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < vec.size(); ++i) {
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
832 KB |
Output is correct |
2 |
Correct |
5 ms |
832 KB |
Output is correct |
3 |
Correct |
5 ms |
832 KB |
Output is correct |
4 |
Correct |
5 ms |
832 KB |
Output is correct |
5 |
Correct |
5 ms |
832 KB |
Output is correct |
6 |
Correct |
5 ms |
832 KB |
Output is correct |
7 |
Correct |
5 ms |
832 KB |
Output is correct |
8 |
Correct |
5 ms |
832 KB |
Output is correct |
9 |
Correct |
5 ms |
832 KB |
Output is correct |
10 |
Correct |
5 ms |
804 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
832 KB |
Output is correct |
22 |
Correct |
5 ms |
832 KB |
Output is correct |
23 |
Correct |
5 ms |
832 KB |
Output is correct |
24 |
Correct |
5 ms |
832 KB |
Output is correct |
25 |
Correct |
4 ms |
832 KB |
Output is correct |
26 |
Correct |
5 ms |
832 KB |
Output is correct |
27 |
Correct |
5 ms |
832 KB |
Output is correct |
28 |
Correct |
5 ms |
832 KB |
Output is correct |
29 |
Correct |
5 ms |
832 KB |
Output is correct |
30 |
Correct |
5 ms |
832 KB |
Output is correct |
31 |
Correct |
5 ms |
832 KB |
Output is correct |
32 |
Correct |
5 ms |
832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
832 KB |
Output is correct |
2 |
Correct |
5 ms |
832 KB |
Output is correct |
3 |
Correct |
5 ms |
832 KB |
Output is correct |
4 |
Correct |
5 ms |
832 KB |
Output is correct |
5 |
Correct |
5 ms |
832 KB |
Output is correct |
6 |
Correct |
5 ms |
832 KB |
Output is correct |
7 |
Correct |
5 ms |
832 KB |
Output is correct |
8 |
Correct |
5 ms |
832 KB |
Output is correct |
9 |
Correct |
5 ms |
832 KB |
Output is correct |
10 |
Correct |
5 ms |
804 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
832 KB |
Output is correct |
22 |
Correct |
5 ms |
832 KB |
Output is correct |
23 |
Correct |
5 ms |
832 KB |
Output is correct |
24 |
Correct |
5 ms |
832 KB |
Output is correct |
25 |
Correct |
4 ms |
832 KB |
Output is correct |
26 |
Correct |
5 ms |
832 KB |
Output is correct |
27 |
Correct |
5 ms |
832 KB |
Output is correct |
28 |
Correct |
5 ms |
832 KB |
Output is correct |
29 |
Correct |
5 ms |
832 KB |
Output is correct |
30 |
Correct |
5 ms |
832 KB |
Output is correct |
31 |
Correct |
5 ms |
832 KB |
Output is correct |
32 |
Correct |
5 ms |
832 KB |
Output is correct |
33 |
Execution timed out |
2105 ms |
109924 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
832 KB |
Output is correct |
2 |
Correct |
5 ms |
832 KB |
Output is correct |
3 |
Correct |
5 ms |
832 KB |
Output is correct |
4 |
Correct |
5 ms |
832 KB |
Output is correct |
5 |
Correct |
5 ms |
832 KB |
Output is correct |
6 |
Correct |
5 ms |
832 KB |
Output is correct |
7 |
Correct |
5 ms |
832 KB |
Output is correct |
8 |
Correct |
5 ms |
832 KB |
Output is correct |
9 |
Correct |
5 ms |
832 KB |
Output is correct |
10 |
Correct |
5 ms |
804 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
5 ms |
832 KB |
Output is correct |
22 |
Correct |
5 ms |
832 KB |
Output is correct |
23 |
Correct |
5 ms |
832 KB |
Output is correct |
24 |
Correct |
5 ms |
832 KB |
Output is correct |
25 |
Correct |
4 ms |
832 KB |
Output is correct |
26 |
Correct |
5 ms |
832 KB |
Output is correct |
27 |
Correct |
5 ms |
832 KB |
Output is correct |
28 |
Correct |
5 ms |
832 KB |
Output is correct |
29 |
Correct |
5 ms |
832 KB |
Output is correct |
30 |
Correct |
5 ms |
832 KB |
Output is correct |
31 |
Correct |
5 ms |
832 KB |
Output is correct |
32 |
Correct |
5 ms |
832 KB |
Output is correct |
33 |
Execution timed out |
2105 ms |
109924 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |