#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
const int MAXN = 2013;
struct point
{
ll x, y, w;
};
int N;
point arr[MAXN];
vpl angs;
ll ans;
bool cmp(point a, point b)
{
return a.x < b.x;
}
bool cmpy(point a, point b)
{
return a.y < b.y;
}
int32_t main()
{
cout << fixed << setprecision(12);
cerr << fixed << setprecision(4);
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N;
FOR(i, 0, N)
{
cin >> arr[i].x >> arr[i].y >> arr[i].w;
ckmax(ans, arr[i].w);
}
sort(arr, arr + N, cmp);
ll sum = 0;
FOR(i, 0, N)
{
sum += arr[i].w;
if (i == N - 1 || arr[i + 1].x != arr[i].x)
{
ckmax(ans, sum);
ckmax(sum, 0);
}
}
sort(arr, arr + N, cmpy);
sum = 0;
FOR(i, 0, N)
{
sum += arr[i].w;
if (i == N - 1 || arr[i + 1].y != arr[i].y)
{
ckmax(ans, sum);
ckmax(sum, 0);
}
}
FOR(i, 0, N)
{
FOR(j, i + 1, N)
{
ll dx = arr[j].x - arr[i].x, dy = arr[i].y - arr[j].y;
if (dx == 0 || dy == 0) continue;
vpl ok;
FOR(k, 0, N)
{
ok.PB({dy * arr[k].x + dx * arr[k].y, arr[k].w});
}
sort(ALL(ok));
// cerr << "OK\n";
// for (pll p : ok)
// {
// cerr << p.fi << ' ' << p.se << endl;
// }
int idx = -1;
FOR(k, 0, N - 1)
{
if (ok[k].fi == ok[k + 1].fi)
{
assert(idx == -1);
idx = k;
}
}
assert(idx != -1);
sum = ok[idx].se + ok[idx + 1].se;
ckmax(ans, sum);
FORD(j, idx, 0)
{
sum += ok[j].se;
ckmax(ans, sum);
}
sum = ok[idx].se + ok[idx + 1].se;
FOR(j, idx + 2, N)
{
sum += ok[j].se;
ckmax(ans, sum);
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Incorrect |
28 ms |
384 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |