#include <bits/stdc++.h>
#define fi first
#define se second
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)
template<typename T>
void __prine_one(const char *&s, const T &x)
{
while (*s == ' ') ++s;
const char *p = s;
int bal = 0;
while (*s)
{
if (*s == '(') ++bal;
else if (*s == ')') --bal;
else if (*s == ',' && bal == 0) break;
++s;
}
cerr.write(p, s - p) << " = " << x;
if (*s == ',')
{
cerr << " , ";
++s;
}
}
template<typename... Args>
void debug(const char *s, Args... args)
{
cerr << "[ ";
int dummy[] = {0, (__prine_one(s, args), 0)...};
(void)dummy;
cerr << " ]\n\n";
}
template<class X>
bool maximize(X &a, const X &b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template<class X>
bool minimize(X &a, const X &b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
// --------------------------------------------------------------------------------------------
const int maxn = 2e3 + 3;
int n;
ll gcd(ll a, ll b)
{
if (b == 0) return a;
return gcd(b, a % b);
}
struct Geo
{
ll x, y, val;
Geo() {}
Geo(ll x, ll y) : x(x), y(y) {}
} a[maxn];
struct Frac
{
ll x, y;
Frac() {}
Frac(ll x, ll y) : x(x), y(y) {}
bool operator < (const Frac &other) const
{
if (y == 0 && other.y == 0) return x < other.x;
if (y == 0) return true;
if (other.y == 0) return false;
ll p1 = x * other.y - other.x * y, p2 = y * other.y;
if (p1 < 0) swap(p1, p2);
return (p1 > 0) && (p2 < 0);
}
bool operator == (const Frac &other) const
{
return x == other.x && y == other.y;
}
};
struct Node
{
ll res, sumL, sumR, sum;
Node() {res = sumL = sumR = sum = 0;}
};
struct Event
{
Frac f; int id;
Frac Tu;
bool operator == (const Event &other) const
{
return f == other.f && id == other.id && Tu == other.Tu;
}
};
vector<pair<Frac, ll>> vec[maxn * maxn];
int POS[maxn];
vector<Event> evs;
// --------------------------------------------------------------------------------------------
namespace SegTree
{
Node seg[maxn << 2];
Node combine(const Node &a, const Node &b)
{
Node c;
c.res = max({a.res, b.res, a.sumR + b.sumL});
c.sumL = max(a.sumL, a.sum + b.sumL);
c.sumR = max(b.sumR, b.sum + a.sumR);
c.sum = a.sum + b.sum;
return c;
}
void upd(int id, int l, int r, int pos, ll val)
{
if (l == r)
{
seg[id].res = seg[id].sumL = seg[id].sumR = max(0ll, val);
seg[id].sum = val;
return;
}
int mid = l + r >> 1;
if (pos <= mid) upd(id << 1, l, mid, pos, val);
else upd(id << 1 | 1, mid + 1, r, pos, val);
seg[id] = combine(seg[id << 1], seg[id << 1 | 1]);
}
ll get(int id, int l, int r, int pos)
{
if (l == r) return seg[id].sum;
int mid = l + r >> 1;
if (pos <= mid) return get(id << 1, l, mid, pos);
return get(id << 1 | 1, mid + 1, r, pos);
}
void DBG()
{
FOR(i, 1, n)
cerr << get(1, 1, n, i) << ' ';
cerr << "\n\n";
}
}
void encode(ll &x, ll &y)
{
ll g = gcd(x, y);
if (g == 0) return;
x /= g;
y /= g;
if (x < 0) x *= -1, y *= -1;
}
void solve()
{
cin >> n;
FOR(i, 1, n)
cin >> a[i].x >> a[i].y >> a[i].val;
sort(a + 1, a + n + 1, [&](const Geo &a, const Geo &b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
});
FOR(i, 1, n - 1)
FOR(j, i + 1, n)
{
Frac V(a[j].y - a[i].y, a[j].x - a[i].x);
if (V.y == 0) continue;
encode(V.x, V.y);
// dbg(i, j, V.x, V.y);
ll tu = a[i].y * V.y - V.x * a[i].x, mau = V.y;
encode(tu, mau);
evs.push_back({V, i, Frac(tu, mau)});
evs.push_back({V, j, Frac(tu, mau)});
}
ll res = 0;
// Initialize
FOR(i, 1, n)
{
SegTree :: upd(1, 1, n, i, a[i].val);
POS[i] = i;
}
res = max(res, SegTree :: seg[1].res);
// FOR(i, 1, n)
// dbg(a[i].x, a[i].y, a[i].val);
// SegTree :: DBG();
// for (const auto &e : slopes)
// dbg(e.x, e.y);
sort(all(evs), [&](const Event &X, const Event &Y) {
if (X.f == Y.f)
{
if (X.Tu == Y.Tu) return a[X.id].x < a[Y.id].x;
return X.Tu < Y.Tu;
}
return X.f < Y.f;
});
evs.erase(unique(all(evs)), evs.end());
FOR(i, 0, (int)evs.size() - 1)
{
int j = i;
while (j + 1 < (int)evs.size() && evs[j + 1].f == evs[i].f && evs[j + 1].Tu == evs[i].Tu)
++j;
FOR(k, 0, j - i - 1 >> 1)
{
int idone = evs[i + k].id, idtwo = evs[j - k].id;
// dbg(idone, idtwo);
SegTree :: upd(1, 1, n, POS[idone], a[idtwo].val);
SegTree :: upd(1, 1, n, POS[idtwo], a[idone].val);
swap(POS[idone], POS[idtwo]);
}
res = max(res, SegTree :: seg[1].res);
i = j;
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TASK "TEST"
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:270:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
270 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp:271:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
271 | freopen(TASK".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |