#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<PP> vpp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define pb emplace_back
#define fi first
#define se second
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
const ll inf=1001001001001001001;
ll gcd(ll a,ll b){
if(b==0)return a;
return gcd(b,a%b);
}
class segtree{
vi seg;ll N=1;
public:
segtree(vi v){
while(N<v.size())N*=2;
seg=vi(N*2-1,-inf);
rep(i,v.size())seg[i+N-1]=v[i];
for(ll i=N-2;i>=0;i--)seg[i]=max(seg[i*2+1],seg[i*2+2]);
}
void add(ll i,ll x){
i+=N-1;
seg[i]+=x;
while(i>0){
i=(i-1)/2;
seg[i]=max(seg[i*2+1],seg[i*2+2]);
}
}
ll get(ll a,ll b,ll k=0,ll l=0,ll r=-1){
if(r==-1)r=N;
if(a<=l&&r<=b)return seg[k];
if(r<=a||b<=l)return -inf;
ll c1=get(a,b,k*2+1,l,(l+r)/2);
ll c2=get(a,b,k*2+2,(l+r)/2,r);
return max(c1,c2);
}
void debug(ll n){
vi res;
rep(i,n)res.pb(seg[i+N-1]);
outv(res);
}
};
int main(){
ll n;cin>>n;
vvi tmp(n,vi(3));
rep(i,n)rep(j,3)cin>>tmp[i][j];
sort(all(tmp));
vp v(n);vi val(n);rep(i,n)v[i]=P(tmp[i][0],tmp[i][1]);rep(i,n)val[i]=tmp[i][2];
vpp srt;
rep(i,n)rep(j,i){
ll a=v[i].fi-v[j].fi,b=v[i].se-v[j].se;
if(a!=0){
ll g=gcd(abs(a),abs(b));
a/=g;b/=g;
srt.pb(P(a,b),P(j,i));
}
else srt.pb(P(1,1001001001),P(j,i));
}
auto cmp=[&](PP a,PP b){
if(a.fi!=b.fi)return a.fi.se*b.fi.fi<a.fi.fi*b.fi.se;
return a.se<b.se;
};
sort(all(srt),cmp);
vi ruil=val,ruir=val;
rep(i,n-1)ruil[i+1]+=ruil[i];
for(int i=n-1;i>0;i--)ruir[i-1]+=ruir[i];
segtree segl(ruil),segr(ruir);
ll ans=0;rep(i,n)chmax(ans,val[i]);rep(i,n)rep(j,i)chmax(ans,val[i]+val[j]);
ll l=0;
vi num(n),mun(n);
rep(i,n)num[i]=mun[i]=i;
while(l<srt.size()){
ll r=l;
while(r+1<srt.size()&&srt[l].fi==srt[r+1].fi)r++;
REP(i,l,r+1){
ll a=srt[i].se.fi,b=srt[i].se.se;
ll A=mun[a],B=mun[b];
chmax(ans,max(0ll,val[a])+max(0ll,val[b])+segr.get(0,A)-segr.get(A,A+1));
chmax(ans,max(0ll,val[a])+max(0ll,val[b])+segl.get(B+1,n)-segl.get(B,B+1));
}
REP(i,l,r+1){
ll a=srt[i].se.fi,b=srt[i].se.se;
ll A=mun[a],B=mun[b];
assert(B-A==1);
swap(num[A],num[B]);
swap(mun[a],mun[b]);
segl.add(A,val[b]-val[a]);
segr.add(B,val[a]-val[b]);
}
assert(l==r);
// outp(srt[l].se);
// out(ans);
// segl.debug(n);
// segr.debug(n);
l=r+1;
}
// outvp(v);outv(val);
out(ans);
}
Compilation message
bulldozer.cpp: In constructor 'segtree::segtree(vi)':
bulldozer.cpp:34:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(N<v.size())N*=2;
| ~^~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:90:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long 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]
90 | while(l<srt.size()){
| ~^~~~~~~~~~~
bulldozer.cpp:92:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long 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]
92 | while(r+1<srt.size()&&srt[l].fi==srt[r+1].fi)r++;
| ~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1000 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
748 KB |
Output is correct |
3 |
Correct |
5 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
4 ms |
748 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
748 KB |
Output is correct |
8 |
Correct |
4 ms |
748 KB |
Output is correct |
9 |
Correct |
4 ms |
748 KB |
Output is correct |
10 |
Correct |
4 ms |
748 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
748 KB |
Output is correct |
22 |
Correct |
4 ms |
748 KB |
Output is correct |
23 |
Correct |
4 ms |
748 KB |
Output is correct |
24 |
Correct |
4 ms |
748 KB |
Output is correct |
25 |
Correct |
4 ms |
748 KB |
Output is correct |
26 |
Correct |
5 ms |
748 KB |
Output is correct |
27 |
Correct |
5 ms |
748 KB |
Output is correct |
28 |
Correct |
4 ms |
748 KB |
Output is correct |
29 |
Correct |
5 ms |
748 KB |
Output is correct |
30 |
Correct |
5 ms |
748 KB |
Output is correct |
31 |
Correct |
4 ms |
748 KB |
Output is correct |
32 |
Correct |
4 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
748 KB |
Output is correct |
3 |
Correct |
5 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
4 ms |
748 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
748 KB |
Output is correct |
8 |
Correct |
4 ms |
748 KB |
Output is correct |
9 |
Correct |
4 ms |
748 KB |
Output is correct |
10 |
Correct |
4 ms |
748 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
748 KB |
Output is correct |
22 |
Correct |
4 ms |
748 KB |
Output is correct |
23 |
Correct |
4 ms |
748 KB |
Output is correct |
24 |
Correct |
4 ms |
748 KB |
Output is correct |
25 |
Correct |
4 ms |
748 KB |
Output is correct |
26 |
Correct |
5 ms |
748 KB |
Output is correct |
27 |
Correct |
5 ms |
748 KB |
Output is correct |
28 |
Correct |
4 ms |
748 KB |
Output is correct |
29 |
Correct |
5 ms |
748 KB |
Output is correct |
30 |
Correct |
5 ms |
748 KB |
Output is correct |
31 |
Correct |
4 ms |
748 KB |
Output is correct |
32 |
Correct |
4 ms |
748 KB |
Output is correct |
33 |
Correct |
1904 ms |
66320 KB |
Output is correct |
34 |
Correct |
1896 ms |
66540 KB |
Output is correct |
35 |
Correct |
1941 ms |
66320 KB |
Output is correct |
36 |
Correct |
1910 ms |
66448 KB |
Output is correct |
37 |
Correct |
1955 ms |
66320 KB |
Output is correct |
38 |
Correct |
1928 ms |
66320 KB |
Output is correct |
39 |
Correct |
1902 ms |
66320 KB |
Output is correct |
40 |
Correct |
1979 ms |
66368 KB |
Output is correct |
41 |
Correct |
1900 ms |
66320 KB |
Output is correct |
42 |
Correct |
1960 ms |
66320 KB |
Output is correct |
43 |
Correct |
1925 ms |
66424 KB |
Output is correct |
44 |
Correct |
1924 ms |
66320 KB |
Output is correct |
45 |
Correct |
1861 ms |
66348 KB |
Output is correct |
46 |
Correct |
1871 ms |
66320 KB |
Output is correct |
47 |
Correct |
1883 ms |
66320 KB |
Output is correct |
48 |
Correct |
1901 ms |
66480 KB |
Output is correct |
49 |
Correct |
1888 ms |
66504 KB |
Output is correct |
50 |
Correct |
1898 ms |
66448 KB |
Output is correct |
51 |
Correct |
1884 ms |
66448 KB |
Output is correct |
52 |
Correct |
1861 ms |
66408 KB |
Output is correct |
53 |
Correct |
1844 ms |
66432 KB |
Output is correct |
54 |
Correct |
1868 ms |
66448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
748 KB |
Output is correct |
2 |
Correct |
4 ms |
748 KB |
Output is correct |
3 |
Correct |
5 ms |
748 KB |
Output is correct |
4 |
Correct |
5 ms |
748 KB |
Output is correct |
5 |
Correct |
4 ms |
748 KB |
Output is correct |
6 |
Correct |
4 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
748 KB |
Output is correct |
8 |
Correct |
4 ms |
748 KB |
Output is correct |
9 |
Correct |
4 ms |
748 KB |
Output is correct |
10 |
Correct |
4 ms |
748 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
4 ms |
748 KB |
Output is correct |
22 |
Correct |
4 ms |
748 KB |
Output is correct |
23 |
Correct |
4 ms |
748 KB |
Output is correct |
24 |
Correct |
4 ms |
748 KB |
Output is correct |
25 |
Correct |
4 ms |
748 KB |
Output is correct |
26 |
Correct |
5 ms |
748 KB |
Output is correct |
27 |
Correct |
5 ms |
748 KB |
Output is correct |
28 |
Correct |
4 ms |
748 KB |
Output is correct |
29 |
Correct |
5 ms |
748 KB |
Output is correct |
30 |
Correct |
5 ms |
748 KB |
Output is correct |
31 |
Correct |
4 ms |
748 KB |
Output is correct |
32 |
Correct |
4 ms |
748 KB |
Output is correct |
33 |
Correct |
1904 ms |
66320 KB |
Output is correct |
34 |
Correct |
1896 ms |
66540 KB |
Output is correct |
35 |
Correct |
1941 ms |
66320 KB |
Output is correct |
36 |
Correct |
1910 ms |
66448 KB |
Output is correct |
37 |
Correct |
1955 ms |
66320 KB |
Output is correct |
38 |
Correct |
1928 ms |
66320 KB |
Output is correct |
39 |
Correct |
1902 ms |
66320 KB |
Output is correct |
40 |
Correct |
1979 ms |
66368 KB |
Output is correct |
41 |
Correct |
1900 ms |
66320 KB |
Output is correct |
42 |
Correct |
1960 ms |
66320 KB |
Output is correct |
43 |
Correct |
1925 ms |
66424 KB |
Output is correct |
44 |
Correct |
1924 ms |
66320 KB |
Output is correct |
45 |
Correct |
1861 ms |
66348 KB |
Output is correct |
46 |
Correct |
1871 ms |
66320 KB |
Output is correct |
47 |
Correct |
1883 ms |
66320 KB |
Output is correct |
48 |
Correct |
1901 ms |
66480 KB |
Output is correct |
49 |
Correct |
1888 ms |
66504 KB |
Output is correct |
50 |
Correct |
1898 ms |
66448 KB |
Output is correct |
51 |
Correct |
1884 ms |
66448 KB |
Output is correct |
52 |
Correct |
1861 ms |
66408 KB |
Output is correct |
53 |
Correct |
1844 ms |
66432 KB |
Output is correct |
54 |
Correct |
1868 ms |
66448 KB |
Output is correct |
55 |
Correct |
1903 ms |
66452 KB |
Output is correct |
56 |
Correct |
1910 ms |
66468 KB |
Output is correct |
57 |
Correct |
1909 ms |
66520 KB |
Output is correct |
58 |
Correct |
1924 ms |
66320 KB |
Output is correct |
59 |
Correct |
1926 ms |
66320 KB |
Output is correct |
60 |
Correct |
1907 ms |
66320 KB |
Output is correct |
61 |
Correct |
1908 ms |
66448 KB |
Output is correct |
62 |
Correct |
1909 ms |
66320 KB |
Output is correct |
63 |
Correct |
1907 ms |
66468 KB |
Output is correct |
64 |
Correct |
1893 ms |
66448 KB |
Output is correct |
65 |
Runtime error |
1356 ms |
128076 KB |
Execution killed with signal 6 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1000 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |