#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<pair<ll, ll>, pair<ll, ll>> Point;
bool comp(Point p1, Point p2) {
return p1.second.second < p2.second.second;
}
ll max_sub_sum(vector<ll> &vals) {
ll S[vals.size()+1];
ll M[vals.size()+1];
S[0] = 0;
M[0] = 0;
for(int i=1;i<=vals.size();i++) {
S[i] = S[i-1]+vals[i-1];
M[i] = min(M[i-1], S[i]);
}
ll ans = 0;
for(int i=0;i<vals.size();i++) {
ans = max(ans, S[i+1] - M[i+1]);
}
return ans;
}
void solve() {
int n; cin >> n;
vector<Point> points;
vector<Point> points2;
for(int i=0;i<n;i++) {
Point p;
long long x, y, w;
cin >> p.first.first >> p.first.second >> p.second.first;
points.push_back(p);
points2.push_back(p);
}
if(n==1) {
cout << max(0LL, points[0].second.first) << endl;
return;
}
ll ans = 0;
for(int k=0;k<n;k++) {
points[k].second.second = points[k].first.second;
}
sort(points.begin(), points.end(), comp);
vector<ll> vals1;
for(int k=0;k<n;k++) {
vals1.push_back(0);
ll X = points[k].second.second;
while(points[k].second.second == X) {
vals1[vals1.size()-1]+=points[k].second.first;
k++;
}
k--;
}
ans = max(ans, max_sub_sum(vals1));
for(int k=0;k<n;k++) {
points[k].second.second = points[k].first.first;
}
sort(points.begin(), points.end(), comp);
vector<ll> vals2;
for(int k=0;k<n;k++) {
vals2.push_back(0);
ll X = points[k].second.second;
while(points[k].second.second == X) {
vals2[vals2.size()-1]+=points[k].second.first;
k++;
}
k--;
}
ans = max(ans, max_sub_sum(vals2));
for(int i=0;i<n;i++) {
for(int j=i+1;j<n;j++) {
pair<ll, ll> dir = {points2[i].first.second - points2[j].first.second, -points2[i].first.first + points2[j].first.first};
if(dir.first != 0 || dir.second != 0) {
for(int k=0;k<n;k++) {
points[k].second.second = dir.first * points[k].first.first + dir.second * points[k].first.second;
}
sort(points.begin(), points.end(), comp);
vector<ll> vals;
for(int k=0;k<n;k++) {
vals.push_back(0);
ll X = points[k].second.second;
while(points[k].second.second == X) {
vals[vals.size()-1]+=points[k].second.first;
k++;
}
k--;
}
ans = max(ans, max_sub_sum(vals));
}
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
// int t; cin >> t;
// while(t--) {
solve();
// }
// char dksfjn;
// cin >> dksfjn;
// }
}
Compilation message
bulldozer.cpp: In function 'll max_sub_sum(std::vector<long long int>&)':
bulldozer.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i=1;i<=vals.size();i++) {
| ~^~~~~~~~~~~~~
bulldozer.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<vals.size();i++) {
| ~^~~~~~~~~~~~
bulldozer.cpp: In function 'void solve()':
bulldozer.cpp:33:19: warning: unused variable 'x' [-Wunused-variable]
33 | long long x, y, w;
| ^
bulldozer.cpp:33:22: warning: unused variable 'y' [-Wunused-variable]
33 | long long x, y, w;
| ^
bulldozer.cpp:33:25: warning: unused variable 'w' [-Wunused-variable]
33 | long long x, y, w;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
464 KB |
Output is correct |
3 |
Correct |
12 ms |
468 KB |
Output is correct |
4 |
Correct |
12 ms |
348 KB |
Output is correct |
5 |
Correct |
15 ms |
344 KB |
Output is correct |
6 |
Correct |
12 ms |
468 KB |
Output is correct |
7 |
Correct |
14 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
348 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
11 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
348 KB |
Output is correct |
3 |
Correct |
28 ms |
472 KB |
Output is correct |
4 |
Correct |
29 ms |
348 KB |
Output is correct |
5 |
Correct |
29 ms |
348 KB |
Output is correct |
6 |
Correct |
28 ms |
472 KB |
Output is correct |
7 |
Correct |
29 ms |
348 KB |
Output is correct |
8 |
Correct |
28 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
344 KB |
Output is correct |
10 |
Correct |
28 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
30 ms |
348 KB |
Output is correct |
22 |
Correct |
26 ms |
348 KB |
Output is correct |
23 |
Correct |
26 ms |
344 KB |
Output is correct |
24 |
Correct |
26 ms |
348 KB |
Output is correct |
25 |
Incorrect |
26 ms |
348 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
348 KB |
Output is correct |
3 |
Correct |
28 ms |
472 KB |
Output is correct |
4 |
Correct |
29 ms |
348 KB |
Output is correct |
5 |
Correct |
29 ms |
348 KB |
Output is correct |
6 |
Correct |
28 ms |
472 KB |
Output is correct |
7 |
Correct |
29 ms |
348 KB |
Output is correct |
8 |
Correct |
28 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
344 KB |
Output is correct |
10 |
Correct |
28 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
30 ms |
348 KB |
Output is correct |
22 |
Correct |
26 ms |
348 KB |
Output is correct |
23 |
Correct |
26 ms |
344 KB |
Output is correct |
24 |
Correct |
26 ms |
348 KB |
Output is correct |
25 |
Incorrect |
26 ms |
348 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
348 KB |
Output is correct |
3 |
Correct |
28 ms |
472 KB |
Output is correct |
4 |
Correct |
29 ms |
348 KB |
Output is correct |
5 |
Correct |
29 ms |
348 KB |
Output is correct |
6 |
Correct |
28 ms |
472 KB |
Output is correct |
7 |
Correct |
29 ms |
348 KB |
Output is correct |
8 |
Correct |
28 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
344 KB |
Output is correct |
10 |
Correct |
28 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
30 ms |
348 KB |
Output is correct |
22 |
Correct |
26 ms |
348 KB |
Output is correct |
23 |
Correct |
26 ms |
344 KB |
Output is correct |
24 |
Correct |
26 ms |
348 KB |
Output is correct |
25 |
Incorrect |
26 ms |
348 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
464 KB |
Output is correct |
3 |
Correct |
12 ms |
468 KB |
Output is correct |
4 |
Correct |
12 ms |
348 KB |
Output is correct |
5 |
Correct |
15 ms |
344 KB |
Output is correct |
6 |
Correct |
12 ms |
468 KB |
Output is correct |
7 |
Correct |
14 ms |
604 KB |
Output is correct |
8 |
Correct |
12 ms |
348 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
11 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |