/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <chrono>
using namespace std;
template<class T1, class T2> inline int chkmin(T1 &x, const T2 &y) {
if (x > y) {
x = y;
return 1;
}
else {
return 0;
}
}
template<class T1, class T2> inline int chkmax(T1 &x, const T2 &y) {
if (x < y) {
x = y;
return 1;
}
else {
return 0;
}
}
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define pb push_back
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout);
template<class iterator> void output(iterator begin, iterator end, ostream &out = cerr) {
while (begin != end) {
out << (*begin) << " ";
begin++;
}
out << endl;
}
template<class T> void output(const T &x, ostream &out = cerr) {
output(x.begin(), x.end(), out);
}
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
const int MAXN = 3005;
struct point
{
int x, y, w;
point(){}
point(int _x, int _y) {
x = _x;
y = _y;
}
};
bool operator <(const point &a, const point &b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
point operator -(const point &a, const point &b) {
return point(a.x - b.x, a.y - b.y);
}
long long vec(const point &a, const point &b) {
return 1LL * a.x * b.y - 1LL * a.y * b.x;
}
int n;
point p[MAXN];
int pos[MAXN];
long long comp(pair<int, int> a, pair<int, int> b) {
point g = p[a.second] - p[a.first];
point g1 = p[b.second] - p[b.first];
return vec(g, g1);
}
long long comp1(pair<int, int> a, pair<int, int> b) {
long long ft = comp(a, b);
if (ft != 0) {
return ft < 0;
} else {
return a < b;
}
}
struct node {
long long sum, pref, suf, val;
node(int x = 0) {
sum = (long long) x;
pref = suf = val = (long long)max(x, 0);
};
friend node operator + (const node &l, const node &r) {
node ans;
ans.sum = l.sum + r.sum;
ans.pref = max(l.pref, l.sum + r.pref);
ans.suf = max(r.suf, r.sum + l.suf);
ans.val = max({l.val, r.val, l.suf + r.pref});
return ans;
}
};
node t[MAXN * 2];
void modify(int v, int l, int r, int pos, int val) {
if (l == r) {
t[v] = node(val);
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) {
modify(v << 1, l, mid, pos, val);
} else {
modify(v << 1 | 1, mid + 1, r, pos, val);
}
t[v] = t[v << 1] + t[v << 1 | 1];
}
int main() {
fast_io();
//read("input");
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].x >> p[i].y >> p[i].w;
}
sort(p + 1, p + n + 1);
vector<pair<int, int> > st;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
st.pb({i, j});
}
}
sort(all(st), comp1);
for (int i = 1; i <= n; i++) {
pos[i] = i;
modify(1, 1, n, i, p[i].w);
}
long long ans = t[1].val;
int i = 0;
while (i < sz(st)) {
vector<pair<int, int> > kek;
kek.pb(st[i]);
while (i + 1 < sz(st) && !comp(st[i], st[i + 1])) {
i++;
kek.pb(st[i]);
}
for (auto x: kek) {
int a = x.first;
int b = x.second;
swap(pos[a], pos[b]);
modify(1, 1, n, pos[a], p[a].w);
modify(1, 1, n, pos[b], p[b].w);
}
chkmax(ans, t[1].val);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2056 ms |
640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2051 ms |
640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2051 ms |
640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2051 ms |
640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2056 ms |
640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |