#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
#define int ll
const int MAX=2000+15;
const int B=500;
const int maxB=1000;
const int N=104;
const int block=450;
const ll inf=1e9;
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int x[MAX],y[MAX],a[MAX];
vector<pair<ld,pii>> slope;
vector<pair<pii,int>> vec;
int pos[MAX];
int f[MAX];
int p[MAX],mn[MAX],mx[MAX];
struct segtree{
struct node{
int pref,suf,sum,ans;
node(){
pref=suf=sum=ans=0;
}
}t[4*MAX];
node mrg(node a,node b){
node res;
res.sum=a.sum+b.sum;
res.ans=max({a.ans,b.ans,a.suf+b.pref});
res.suf=max(b.suf,b.sum+a.suf);
res.pref=max(a.pref,a.sum+b.pref);
return res;
}
void update(int v,int tl,int tr,int pos,int x){
if(tl==tr){
t[v].pref=max(0ll,x);
t[v].suf=max(0ll,x);
t[v].ans=max(0ll,x);
t[v].sum=x;
return;
}
int tm=(tl+tr)/2;
if(pos<=tm)update(2*v,tl,tm,pos,x);
else update(2*v+1,tm+1,tr,pos,x);
t[v]=mrg(t[2*v],t[2*v+1]);
}
}t;
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i]>>a[i];
vec.pb({{x[i],-y[i]},i});
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(x[i]!=x[j]){
ld k=(0.0+y[i]-y[j])/(x[i]-x[j]);
slope.pb({k,{i,j}});
// cout<<i<<" "<<j<<" "<<k<<"\n";
}
}
}
sort(all(vec));
for(int i=0;i<n;i++){
f[i+1]=a[vec[i].S];
t.update(1,1,n,i+1,f[i+1]);
pos[vec[i].S]=i+1;
}
sort(all(slope));
// reverse(all(slope));
int ans=t.t[1].ans;
for(int k=0;k<sz(slope);k++){
int i=slope[k].S.F,j=slope[k].S.S;
// cout<<slope[k].F<<" "<<pos[i]<<" "<<pos[j]<<"\n";
swap(f[pos[i]],f[pos[j]]);
swap(pos[i],pos[j]);
t.update(1,1,n,pos[i],f[pos[i]]);
t.update(1,1,n,pos[j],f[pos[j]]);
if(k==sz(slope)-1||slope[k].F!=slope[k+1].F)ans=max(ans,t.t[1].ans);
// cout<<t.t[1].ans<<"\n";
// for(int i=1;i<=n;i++){
// cout<<f[i]<<" ";
// }
// cout<<"\n";
}
cout<<ans<<"\n";
}
signed main(){
// freopen("triangles.in","r",stdin);
// freopen("triangles.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// prec();
int t=1;
// cin>>t;
while(t--){
solve();
}
}
Compilation message
bulldozer.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize("Ofast")
|
bulldozer.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
4 | #pragma target("avx2")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
2 ms |
1116 KB |
Output is correct |
5 |
Correct |
2 ms |
1116 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
2 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
2 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
1368 KB |
Output is correct |
24 |
Correct |
2 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
1116 KB |
Output is correct |
26 |
Correct |
2 ms |
1116 KB |
Output is correct |
27 |
Correct |
2 ms |
1116 KB |
Output is correct |
28 |
Correct |
2 ms |
940 KB |
Output is correct |
29 |
Correct |
2 ms |
1112 KB |
Output is correct |
30 |
Correct |
2 ms |
1116 KB |
Output is correct |
31 |
Correct |
2 ms |
1116 KB |
Output is correct |
32 |
Correct |
2 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
2 ms |
1116 KB |
Output is correct |
5 |
Correct |
2 ms |
1116 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
2 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
2 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
1368 KB |
Output is correct |
24 |
Correct |
2 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
1116 KB |
Output is correct |
26 |
Correct |
2 ms |
1116 KB |
Output is correct |
27 |
Correct |
2 ms |
1116 KB |
Output is correct |
28 |
Correct |
2 ms |
940 KB |
Output is correct |
29 |
Correct |
2 ms |
1112 KB |
Output is correct |
30 |
Correct |
2 ms |
1116 KB |
Output is correct |
31 |
Correct |
2 ms |
1116 KB |
Output is correct |
32 |
Correct |
2 ms |
1112 KB |
Output is correct |
33 |
Correct |
774 ms |
68204 KB |
Output is correct |
34 |
Correct |
758 ms |
67640 KB |
Output is correct |
35 |
Correct |
770 ms |
67236 KB |
Output is correct |
36 |
Correct |
793 ms |
67772 KB |
Output is correct |
37 |
Correct |
773 ms |
68028 KB |
Output is correct |
38 |
Correct |
764 ms |
67244 KB |
Output is correct |
39 |
Correct |
767 ms |
66920 KB |
Output is correct |
40 |
Correct |
781 ms |
67772 KB |
Output is correct |
41 |
Correct |
763 ms |
66748 KB |
Output is correct |
42 |
Correct |
770 ms |
68008 KB |
Output is correct |
43 |
Correct |
785 ms |
66732 KB |
Output is correct |
44 |
Correct |
786 ms |
68536 KB |
Output is correct |
45 |
Correct |
767 ms |
68564 KB |
Output is correct |
46 |
Correct |
759 ms |
68004 KB |
Output is correct |
47 |
Correct |
761 ms |
68016 KB |
Output is correct |
48 |
Correct |
762 ms |
67232 KB |
Output is correct |
49 |
Correct |
760 ms |
68020 KB |
Output is correct |
50 |
Correct |
768 ms |
67504 KB |
Output is correct |
51 |
Correct |
764 ms |
67816 KB |
Output is correct |
52 |
Correct |
773 ms |
67504 KB |
Output is correct |
53 |
Correct |
776 ms |
68556 KB |
Output is correct |
54 |
Correct |
790 ms |
68760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
2 ms |
1116 KB |
Output is correct |
5 |
Correct |
2 ms |
1116 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
2 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
2 ms |
1116 KB |
Output is correct |
23 |
Correct |
2 ms |
1368 KB |
Output is correct |
24 |
Correct |
2 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
1116 KB |
Output is correct |
26 |
Correct |
2 ms |
1116 KB |
Output is correct |
27 |
Correct |
2 ms |
1116 KB |
Output is correct |
28 |
Correct |
2 ms |
940 KB |
Output is correct |
29 |
Correct |
2 ms |
1112 KB |
Output is correct |
30 |
Correct |
2 ms |
1116 KB |
Output is correct |
31 |
Correct |
2 ms |
1116 KB |
Output is correct |
32 |
Correct |
2 ms |
1112 KB |
Output is correct |
33 |
Correct |
774 ms |
68204 KB |
Output is correct |
34 |
Correct |
758 ms |
67640 KB |
Output is correct |
35 |
Correct |
770 ms |
67236 KB |
Output is correct |
36 |
Correct |
793 ms |
67772 KB |
Output is correct |
37 |
Correct |
773 ms |
68028 KB |
Output is correct |
38 |
Correct |
764 ms |
67244 KB |
Output is correct |
39 |
Correct |
767 ms |
66920 KB |
Output is correct |
40 |
Correct |
781 ms |
67772 KB |
Output is correct |
41 |
Correct |
763 ms |
66748 KB |
Output is correct |
42 |
Correct |
770 ms |
68008 KB |
Output is correct |
43 |
Correct |
785 ms |
66732 KB |
Output is correct |
44 |
Correct |
786 ms |
68536 KB |
Output is correct |
45 |
Correct |
767 ms |
68564 KB |
Output is correct |
46 |
Correct |
759 ms |
68004 KB |
Output is correct |
47 |
Correct |
761 ms |
68016 KB |
Output is correct |
48 |
Correct |
762 ms |
67232 KB |
Output is correct |
49 |
Correct |
760 ms |
68020 KB |
Output is correct |
50 |
Correct |
768 ms |
67504 KB |
Output is correct |
51 |
Correct |
764 ms |
67816 KB |
Output is correct |
52 |
Correct |
773 ms |
67504 KB |
Output is correct |
53 |
Correct |
776 ms |
68556 KB |
Output is correct |
54 |
Correct |
790 ms |
68760 KB |
Output is correct |
55 |
Correct |
764 ms |
68408 KB |
Output is correct |
56 |
Correct |
765 ms |
66736 KB |
Output is correct |
57 |
Correct |
770 ms |
68176 KB |
Output is correct |
58 |
Correct |
763 ms |
67988 KB |
Output is correct |
59 |
Correct |
800 ms |
68400 KB |
Output is correct |
60 |
Correct |
770 ms |
68140 KB |
Output is correct |
61 |
Correct |
784 ms |
67748 KB |
Output is correct |
62 |
Correct |
765 ms |
68020 KB |
Output is correct |
63 |
Correct |
776 ms |
68272 KB |
Output is correct |
64 |
Correct |
801 ms |
68196 KB |
Output is correct |
65 |
Incorrect |
774 ms |
68540 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |