#include <bits/stdc++.h>
#define dbg(x) cerr << #x << ": " << x << "\n";
using namespace std;
long long calc_dis(long long x1, long long x2, long long y1, long long y2, long long x, long long y){
long long num = abs((x2 - x1) * (y1 - y) - (x1 - x) * (y2 - y1));
return num;
}
int sign(long long x1, long long x2, long long y1, long long y2, long long x, long long y){
long long cruz = (x2 - x1) * (y - y1) - (y2 - y1) * (x - x1);
if(cruz > 0) return -1;
if(cruz < 0) return 1;
return 0;
}
void kadane(const vector<pair<long long, long long>> &arr, long long &ans){
long long aux = 0;
for(int i = 0; i < (int)arr.size(); i++){
aux = max(aux + arr[i].second, arr[i].second);
ans = max(ans, aux);
}
}
int main(){
int n;
cin >> n;
vector<long long> x(n), y(n), v(n);
long long ans = 0;
for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> v[i];
vector<pair<long long, long long>> noche;
map<long long, long long> otro;
for(int i = 0; i < n; i++){
otro[x[i]] += v[i];
}
for(const auto &[a, b] : otro){
noche.push_back({a, b});
}
sort(noche.begin(), noche.end());
kadane(noche, ans);
//dbg(ans);
string linea = "=============";
for(int i = 0; i < n - 1; i++){
for(int j = i + 1; j < n; j++){
if(x[i] == x[j]) continue;
//dbg(i);
//dbg(j);
vector<pair<long long, long long>> aux;
map<long long, long long> check;
check[0] = v[i] + v[j];
//dbg(v[i]);
//dbg(v[j]);
//dbg(check[0]);
for(int k = 0; k < n; k++){
if(k == i or k == j) continue;
long long sgn = sign(x[i], x[j], y[i], y[j], x[k], y[k]);
long long dis = calc_dis(x[i], x[j], y[i], y[j], x[k], y[k]);
long long ago = sgn * dis;
//dbg(v[k]);
check[ago] += v[k];
}
for(const auto &[a, b] : check){
aux.push_back({a, b});
}
sort(aux.begin(), aux.end());
kadane(aux, ans);
//dbg(ans);
//dbg(linea);
}
}
cout << ans;
return 0;
}
# | 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... |