#include <bits/stdc++.h>
//#include "fish.h"
using namespace std;
#define pb push_back
#define mp make_pair
vector<pair<int,long long> > arr[100005];
long long qry(int col,int height){ //prefixsum of col to height
if (arr[col].empty()) return 0;
pair<int,long long> lol=mp(height,1e18);
int pos=upper_bound(arr[col].begin(),arr[col].end(),lol)-arr[col].begin();
pos--;
return arr[col][pos].second;
}
vector<long long> dp1[100005]; //col,height,increasing
vector<long long> dp2[100005]; //col,height,decreasing
vector<long long> whack[100005];
long long max_weights(int n,int m,vector<int> x,vector<int> y,vector<int> w){
for (int i=0;i<m;i++){
x[i]++;
y[i]++;
arr[x[i]].pb(mp(y[i],w[i]));
}
for (int i=1;i<=n;i++){
arr[i].pb(mp(0,0));
sort(arr[i].begin(),arr[i].end());
for (int j=1;j<(int)arr[i].size();j++){
arr[i][j].second+=arr[i][j-1].second;
}
for (auto j:arr[i]){
whack[i].pb(j.first);
whack[i+1].pb(j.first);
whack[i-1].pb(j.first);
}
}
for (int i=0;i<=n;i++){
sort(whack[i].begin(),whack[i].end());
whack[i].resize(unique(whack[i].begin(),whack[i].end())-whack[i].begin());
for (int j=0;j<(int) whack[i].size();j++){
dp1[i].pb(0);
dp2[i].pb(0);
}
}
for (int i=1;i<=n;i++){ //col
long long maxi=0,id=0;
for (int j=0;j<(int)whack[i].size();j++){
int k=whack[i][j];
while (id<(int)whack[i-1].size() && whack[i-1][id]<=k){
maxi=max(maxi,dp1[i-1][id]-qry(i,whack[i-1][id])-qry(i-1,whack[i-1][id]));
id++;
}
dp1[i][j]=maxi+qry(i-1,k)+qry(i+1,k);
}
/*
for (int j=0;j<=n;j++){
maxi=max(maxi,dp1[i-1][j]-qry(i,j)-qry(i-1,j));
if (i>=2){
maxi=max(maxi,dp2[i-2][j]-qry(i-1,j));
}
dp1[i][j]=maxi+qry(i-1,j)+qry(i+1,j);
}
*/
if (i>=2){
maxi=0;
id=whack[i-2].size()-1;
for (int j=whack[i].size()-1;j>=0;j--){
int k=whack[i][j];
while (id>=0 && whack[i-2][id]>=k){
maxi=max(maxi,dp2[i-2][id]);
id--;
}
dp1[i][j]=max(dp1[i][j],maxi+qry(i+1,k));
}
/*
for (int j=n;j>=0;j--){
maxi=max(maxi,dp2[i-2][j]);
dp1[i][j]=max(dp1[i][j],maxi+qry(i+1,j));
}
*/
}
maxi=0;
id=whack[i-1].size()-1;
for (int j=whack[i].size()-1;j>=0;j--){
int k=whack[i][j];
while (id>=0 && whack[i-1][id]>=k){
maxi=max(maxi,dp2[i-1][id]);
id--;
}
dp2[i][j]=maxi+qry(i+1,k)-qry(i,k);
}
/*
for (int j=n;j>=0;j--){
maxi=max(maxi,dp2[i-1][j]);
dp2[i][j]=maxi+qry(i+1,j)-qry(i,j);
}
*/
for (int j=0;j<(int)whack[i].size();j++){
dp2[i][j]=max(dp2[i][j],dp1[i][j]);
}
}
long long ans=0;
for (int j=0;j<(int)dp2[n].size();j++){
ans=max(ans,dp2[n][j]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
31632 KB |
Output is correct |
2 |
Correct |
130 ms |
34924 KB |
Output is correct |
3 |
Correct |
38 ms |
23664 KB |
Output is correct |
4 |
Correct |
37 ms |
23760 KB |
Output is correct |
5 |
Correct |
332 ms |
59088 KB |
Output is correct |
6 |
Correct |
359 ms |
65444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
188 ms |
38316 KB |
Output is correct |
3 |
Correct |
217 ms |
42856 KB |
Output is correct |
4 |
Correct |
100 ms |
31672 KB |
Output is correct |
5 |
Correct |
118 ms |
35028 KB |
Output is correct |
6 |
Correct |
5 ms |
9668 KB |
Output is correct |
7 |
Correct |
6 ms |
9684 KB |
Output is correct |
8 |
Correct |
6 ms |
9692 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
39 ms |
23660 KB |
Output is correct |
11 |
Correct |
36 ms |
23792 KB |
Output is correct |
12 |
Correct |
107 ms |
31676 KB |
Output is correct |
13 |
Correct |
130 ms |
35032 KB |
Output is correct |
14 |
Correct |
138 ms |
32484 KB |
Output is correct |
15 |
Correct |
120 ms |
32648 KB |
Output is correct |
16 |
Correct |
108 ms |
32500 KB |
Output is correct |
17 |
Correct |
124 ms |
34636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
23772 KB |
Output is correct |
2 |
Correct |
41 ms |
23764 KB |
Output is correct |
3 |
Correct |
69 ms |
26252 KB |
Output is correct |
4 |
Correct |
62 ms |
26328 KB |
Output is correct |
5 |
Correct |
96 ms |
31320 KB |
Output is correct |
6 |
Correct |
109 ms |
31432 KB |
Output is correct |
7 |
Correct |
110 ms |
31372 KB |
Output is correct |
8 |
Correct |
161 ms |
31388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
7 ms |
9684 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Incorrect |
6 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '278622587073', found: '278080972720' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
7 ms |
9684 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Incorrect |
6 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '278622587073', found: '278080972720' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
7 ms |
9684 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Incorrect |
6 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '278622587073', found: '278080972720' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
23772 KB |
Output is correct |
2 |
Correct |
41 ms |
23764 KB |
Output is correct |
3 |
Correct |
69 ms |
26252 KB |
Output is correct |
4 |
Correct |
62 ms |
26328 KB |
Output is correct |
5 |
Correct |
96 ms |
31320 KB |
Output is correct |
6 |
Correct |
109 ms |
31432 KB |
Output is correct |
7 |
Correct |
110 ms |
31372 KB |
Output is correct |
8 |
Correct |
161 ms |
31388 KB |
Output is correct |
9 |
Correct |
125 ms |
34856 KB |
Output is correct |
10 |
Correct |
112 ms |
27896 KB |
Output is correct |
11 |
Correct |
197 ms |
46244 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
5 ms |
9684 KB |
Output is correct |
14 |
Correct |
7 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9684 KB |
Output is correct |
16 |
Correct |
6 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
40 ms |
23768 KB |
Output is correct |
19 |
Correct |
37 ms |
23756 KB |
Output is correct |
20 |
Correct |
38 ms |
23720 KB |
Output is correct |
21 |
Correct |
43 ms |
23780 KB |
Output is correct |
22 |
Incorrect |
168 ms |
35964 KB |
1st lines differ - on the 1st token, expected: '45561826463480', found: '45419180086758' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
31632 KB |
Output is correct |
2 |
Correct |
130 ms |
34924 KB |
Output is correct |
3 |
Correct |
38 ms |
23664 KB |
Output is correct |
4 |
Correct |
37 ms |
23760 KB |
Output is correct |
5 |
Correct |
332 ms |
59088 KB |
Output is correct |
6 |
Correct |
359 ms |
65444 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
188 ms |
38316 KB |
Output is correct |
9 |
Correct |
217 ms |
42856 KB |
Output is correct |
10 |
Correct |
100 ms |
31672 KB |
Output is correct |
11 |
Correct |
118 ms |
35028 KB |
Output is correct |
12 |
Correct |
5 ms |
9668 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
6 ms |
9692 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
39 ms |
23660 KB |
Output is correct |
17 |
Correct |
36 ms |
23792 KB |
Output is correct |
18 |
Correct |
107 ms |
31676 KB |
Output is correct |
19 |
Correct |
130 ms |
35032 KB |
Output is correct |
20 |
Correct |
138 ms |
32484 KB |
Output is correct |
21 |
Correct |
120 ms |
32648 KB |
Output is correct |
22 |
Correct |
108 ms |
32500 KB |
Output is correct |
23 |
Correct |
124 ms |
34636 KB |
Output is correct |
24 |
Correct |
39 ms |
23772 KB |
Output is correct |
25 |
Correct |
41 ms |
23764 KB |
Output is correct |
26 |
Correct |
69 ms |
26252 KB |
Output is correct |
27 |
Correct |
62 ms |
26328 KB |
Output is correct |
28 |
Correct |
96 ms |
31320 KB |
Output is correct |
29 |
Correct |
109 ms |
31432 KB |
Output is correct |
30 |
Correct |
110 ms |
31372 KB |
Output is correct |
31 |
Correct |
161 ms |
31388 KB |
Output is correct |
32 |
Correct |
5 ms |
9684 KB |
Output is correct |
33 |
Correct |
5 ms |
9684 KB |
Output is correct |
34 |
Correct |
5 ms |
9684 KB |
Output is correct |
35 |
Correct |
5 ms |
9684 KB |
Output is correct |
36 |
Correct |
5 ms |
9684 KB |
Output is correct |
37 |
Correct |
5 ms |
9684 KB |
Output is correct |
38 |
Correct |
5 ms |
9684 KB |
Output is correct |
39 |
Correct |
5 ms |
9684 KB |
Output is correct |
40 |
Correct |
7 ms |
9684 KB |
Output is correct |
41 |
Correct |
7 ms |
9940 KB |
Output is correct |
42 |
Incorrect |
6 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '278622587073', found: '278080972720' |
43 |
Halted |
0 ms |
0 KB |
- |