# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338504 | kiennguyen246 | Bulldozer (JOI17_bulldozer) | C++14 | 258 ms | 364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* \author : Nguyen Duc Kien
* \date : 23/12/2020
* \version : 6.3.1
*/
///Task name
#define TASK "BULLDOZER"
/**--------------------------------------------------**/
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
const int maxn = 2005;
const int infi = 1e9 + 69;
int n;
struct point
{
int x, y, w;
void inp()
{
cin >> x >> y >> w;
}
}a[maxn];
struct line
{
long long a, b, c;
void make_line(point A, point B)
{
int ux = B.x - A.x;
int uy = B.y - A.y;
a = -uy, b = ux;
c = a * A.x + b * A.y;
c = -c;
}
///Raw distance (without abs)
double pos(point A)
{
return double(a * A.x + b * A.y + c) / hypot(abs(a), abs(b));
}
}d;
bool by_x(point u, point v)
{
return (u.x < v.x);
}
bool by_pos(point u, point v)
{
return (d.pos(u) < d.pos(v));
}
namespace Sub1
{
long long sx[maxn], res;
void Main()
{
sort(a + 1, a + n + 1, by_x);
for (int i = 1; i <= n; i ++)
sx[i] = sx[i - 1] + a[i].w;
for (int i = 1; i <= n; i ++)
for (int j = i; j <= n; j ++)
res = max(res, sx[j] - sx[i - 1]);
cout << res;
}
}
namespace Sub2
{
point b[maxn];
int w[maxn], cnt;
void Main()
{
b[0] = {-180571500, 708072270, 0};
long long res = 0;
for (int i = 1; i <= n; i ++) res = max(res, 1ll * b[i].w);
for (int i = 1; i <= n; i ++)
for (int j = i + 1; j <= n; j ++)
{
d.make_line(a[i], a[j]);
for (int t = 1; t <= n; t ++) b[t] = a[t];
sort(b + 1, b + n + 1, by_pos);
cnt = 0;
for (int k = 1; k <= n; k ++)
{
if (abs(d.pos(b[k])) <= 1e-15 || abs(d.pos(b[k - 1])) <= 1e-15) w[++cnt] = b[k].w;
else w[cnt] += b[k].w;
}
long long cur = 0;
for (int k = 1; k <= cnt; k ++)
{
cur += w[k];
res = max(res, cur);
if (cur < 0) cur = 0;
}
}
cout << res;
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cerr << "Processing...\n\n";
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; i ++) a[i].inp();
bool all_ox = 1;
for (int i = 1; i <= n; i ++)
if (a[i].y != 0) all_ox = 0;
if (all_ox) Sub1::Main();
else Sub2::Main();
cerr << "\n\n--------------\n";
return 0;
}
Compilation message (stderr)
# | 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... |