#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
int N;
int cnt[2020], t;
LL ans;
struct Point{
LL x, y, w;
int p, q;
} P[2020];
vector<Point> E;
struct Node{
LL Lmax, Rmax, Sum, Max;
Node operator+(const Node &r)const{
Node ret;
ret.Lmax = max(Lmax, Sum+r.Lmax);
ret.Rmax = max(r.Rmax, Rmax+r.Sum);
ret.Sum = Sum + r.Sum;
ret.Max = max(Max, r.Max);
ret.Max = max(ret.Max, Rmax+r.Lmax);
return ret;
}
} T[10101];
void update(int id, int s, int e, int t, LL v){
if (t < s || e < t) return;
if (s == e){
T[id].Sum += v;
T[id].Lmax = max(0ll, T[id].Sum);
T[id].Rmax = max(0ll, T[id].Sum);
T[id].Max = max(0ll, T[id].Sum);
return;
}
int mid = (s+e)/2;
update(id*2, s, mid, t, v);
update(id*2+1, mid+1, e, t, v);
T[id] = T[id*2] + T[id*2+1];
}
int main(){
scanf("%d", &N);
for (int i=1; i<=N; i++) scanf("%lld %lld %lld", &P[i].x, &P[i].y, &P[i].w);
sort(P+1, P+N+1, [&](Point a, Point b){
if (a.x == b.x) return a.y > b.y;
return a.x < b.x;
});
for (int i=1; i<N; i++) for (int j=i+1; j<=N; j++){
E.push_back((Point){P[j].x-P[i].x, P[j].y-P[i].y, 0, i, j});
cnt[j]++;
}
sort(E.begin(), E.end(), [&](Point a, Point b){
if (a.x == 0 && b.x == 0) return a.y < b.y;
if (a.x == 0) return true;
if (b.x == 0) return false;
return a.y*b.x < b.y*a.x;
});
for (int i=1; i<=N; i++) update(1, 0, N, cnt[i], P[i].w);
while (t < (int)E.size()){
LL dx=E[t].x, dy=E[t].y;
for (int i=t; i<(int)E.size() && (E[i].y*dx == dy*E[i].x || (dx == 0 && E[i].x == 0)); i++){
update(1, 0, N, cnt[E[i].q], -P[E[i].q].w);
cnt[E[i].q]--;
update(1, 0, N, cnt[E[i].q], P[E[i].q].w);
}
ans = max(ans, T[1].Max);
for (; t<(int)E.size() && (E[t].y*dx == dy*E[t].x || (dx == 0 && E[t].x == 0)); t++){
update(1, 0, N, cnt[E[t].p], -P[E[t].p].w);
cnt[E[t].p]++;
update(1, 0, N, cnt[E[t].p], P[E[t].p].w);
}
ans = max(ans, T[1].Max);
}
printf("%lld\n", ans);
return 0;
}
Compilation message
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
bulldozer.cpp:45:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1; i<=N; i++) scanf("%lld %lld %lld", &P[i].x, &P[i].y, &P[i].w);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
760 KB |
Output is correct |
2 |
Correct |
5 ms |
760 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
14 ms |
760 KB |
Output is correct |
5 |
Correct |
5 ms |
764 KB |
Output is correct |
6 |
Correct |
5 ms |
760 KB |
Output is correct |
7 |
Correct |
8 ms |
760 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
5 ms |
760 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
764 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
6 ms |
760 KB |
Output is correct |
4 |
Correct |
6 ms |
760 KB |
Output is correct |
5 |
Correct |
6 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
760 KB |
Output is correct |
7 |
Correct |
5 ms |
760 KB |
Output is correct |
8 |
Correct |
6 ms |
760 KB |
Output is correct |
9 |
Correct |
6 ms |
760 KB |
Output is correct |
10 |
Correct |
6 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
764 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
6 ms |
760 KB |
Output is correct |
4 |
Correct |
6 ms |
760 KB |
Output is correct |
5 |
Correct |
6 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
760 KB |
Output is correct |
7 |
Correct |
5 ms |
760 KB |
Output is correct |
8 |
Correct |
6 ms |
760 KB |
Output is correct |
9 |
Correct |
6 ms |
760 KB |
Output is correct |
10 |
Correct |
6 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
764 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
6 ms |
760 KB |
Output is correct |
4 |
Correct |
6 ms |
760 KB |
Output is correct |
5 |
Correct |
6 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
760 KB |
Output is correct |
7 |
Correct |
5 ms |
760 KB |
Output is correct |
8 |
Correct |
6 ms |
760 KB |
Output is correct |
9 |
Correct |
6 ms |
760 KB |
Output is correct |
10 |
Correct |
6 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
760 KB |
Output is correct |
2 |
Correct |
5 ms |
760 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
14 ms |
760 KB |
Output is correct |
5 |
Correct |
5 ms |
764 KB |
Output is correct |
6 |
Correct |
5 ms |
760 KB |
Output is correct |
7 |
Correct |
8 ms |
760 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
5 ms |
760 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |