This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define task "truffle"
#define etr "\n"
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define bg begin
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define lwb lower_bound
#define upb upper_bound
#define range(x, l, r) x+l, x+1+r
#define all(x) (x).bg(), (x).end()
#define compact(x) x.resize(unique(all(x)) - (x).bg())
#define sq(x) ((x)*(x))
auto start = chrono::steady_clock::now();
void start_timer()
{
start = chrono::steady_clock::now();
}
ld elapsed()
{
auto current = chrono::steady_clock::now();
ld duration = chrono::duration_cast<chrono::nanoseconds>(current - start).count();
return duration / 1e9;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void freop()
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
template<class U, class V> istream& operator >> (istream& in, pair<U, V>& p)
{
in >> p.fi >> p.se;
return in;
}
template<class U, class V> ostream& operator << (ostream& out, pair<U, V> p)
{
out << "{" << p.fi << ' ' << p.se << "}";
return out;
}
template<class T> ostream& operator << (ostream& out, vector<T>& v)
{
out << "{";
for (int i=0; i<v.size(); i++)
{
out << v[i];
if (i != v.size() - 1) out << ", ";
}
out << "}";
return out;
}
const int N=2e3, M=1e5, mod=1e9+7;
int n;
array<ll, 3> a[N+5];
namespace Sub1
{
bool check()
{
for (int i=2; i<=n; i++)
{
if (a[i][1] != a[i-1][1]) return false;
}
return true;
}
void solve()
{
sort(range(a, 1, n));
ll Min = 0, val = 0, res = 0;
for (int i=1; i<=n; i++)
{
val += a[i][2];
if (i == n || a[i][0] != a[i+1][0]) res = max(res, val - Min), Min = min(val, Min);
}
cout << res;
}
}
namespace Sub2
{
array<ll, 3> b[N+5];
inline ll f(ll x, ll y, ll u, ll v)
{
ll res = 0;
for (int k=1; k<=n; k++)
{
b[k] = a[k];
b[k][0] = a[k][0] * u + a[k][1] * v;
b[k][1] = a[k][0] * x + a[k][1] * y;
}
sort(range(b, 1, n));
ll Min = 0, val = 0;
for (int k=1; k<=n; k++)
{
val += b[k][2];
if (k == n || b[k][0] != b[k+1][0]) res = max(res, val - Min), Min = min(val, Min);
}
return res;
}
void solve()
{
ll res = 0;
for (int i=1; i<=n; i++)
{
for (int j=1; j<i; j++)
{
ll x = a[i][0] - a[j][0], y = a[i][1] - a[j][1], u = -y, v = x;
res = max({res, f(x, y, u, v), f(u, v, x, y)});
}
}
cout << res;
}
}
namespace Heuristic
{
array<ll, 3> b[N+5];
inline ll f(ll x, ll y, ll u, ll v)
{
ll res = 0;
for (int k=1; k<=n; k++)
{
b[k] = a[k];
b[k][0] = a[k][0] * u + a[k][1] * v;
b[k][1] = a[k][0] * x + a[k][1] * y;
}
sort(range(b, 1, n));
ll Min = 0, val = 0;
for (int k=1; k<=n; k++)
{
val += b[k][2];
if (k == n || b[k][0] != b[k+1][0]) res = max(res, val - Min), Min = min(val, Min);
}
return res;
}
void solve()
{
shuffle(range(a, 1, n), rng);
ll res = 0;
for (int i=1; i<=n; i++)
{
for (int j=1; j<=i; j++)
{
if (i == j) continue;
ll x = a[i][0] - a[j][0], y = a[i][1] - a[j][1], u = -y, v = x;
res = max({res, f(x, y, u, v), f(u, v, x, y)});
}
if (elapsed() > 0.85) break;
}
cout << res;
}
}
void process()
{
cin >> n;
for (int i=1; i<=n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
if (Sub1::check()) Sub1::solve();
else if (n <= 100) Sub2::solve();
else Heuristic::solve();
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1; //cin >> t;
while (t--) process();
return 0;
}
Compilation message (stderr)
bulldozer.cpp: In function 'void freop()':
bulldozer.cpp:44:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | 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... |