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;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e3+7;
pair<pair<ll,ll>,ll>T[LIM];
ll trmi[4*LIM], trma[4*LIM], trans[4*LIM], pos[LIM], N=1;
ll ilo(pair<ll,ll>a, pair<ll,ll>b) {
return a.st*b.nd-a.nd*b.st;
}
bool srt(pair<pair<ll,ll>,pair<ll,ll>>a, pair<pair<ll,ll>,pair<ll,ll>>b) {
if(ilo(a.st, b.st)==0) return a.nd<b.nd;
return ilo(a.st, b.st)>0;
}
void licz(int v) {
trmi[v]=min(trmi[2*v], trmi[2*v+1]);
trma[v]=max(trma[2*v], trma[2*v+1]);
trans[v]=max(max(trans[2*v], trans[2*v+1]), trma[2*v+1]-trmi[2*v]);
}
void upd(int v, ll x) {
v+=N;
trmi[v]+=x;
trma[v]+=x;
v/=2;
while(v) {
licz(v);
v/=2;
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
while(N<n) N*=2;
rep(i, n) cin >> T[i].st.st >> T[i].st.nd >> T[i].nd;
rep(i, n) swap(T[i].st.st, T[i].st.nd);
sort(T, T+n);
rep(i, n) swap(T[i].st.st, T[i].st.nd);
vector<pair<pair<ll,ll>,pair<ll,ll>>>V;
rep(i, n) rep(j, i) V.pb({{T[i].st.st-T[j].st.st, T[i].st.nd-T[j].st.nd}, {j, i}});
sort(all(V), srt);
rep(i, n) {
pos[i]=i;
trmi[N+i]=trma[N+i]=T[i].nd+trmi[N+i-1];
}
for(int i=N-1; i; --i) licz(i);
ll ans=max(trans[1], trma[1]);
rep(i, V.size()) {
int l=i;
while(l<V.size() && ilo(V[l].st, V[i].st)==0) {
upd(pos[V[l].nd.st], T[V[l].nd.nd].nd-T[V[l].nd.st].nd);
swap(pos[V[l].nd.st], pos[V[l].nd.nd]);
++l;
}
ans=max(ans, max(trans[1], trma[1]));
i=l-1;
}
cout << ans << '\n';
}
Compilation message (stderr)
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
bulldozer.cpp:53:3: note: in expansion of macro 'rep'
53 | rep(i, V.size()) {
| ^~~
bulldozer.cpp:55:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | while(l<V.size() && ilo(V[l].st, V[i].st)==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... |