#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
typedef long long lint;
typedef pair<lint,lint> ii;
struct state{
lint h, P, D, I;
bool operator < (state &b){
return this->h < b.h;
}
bool operator == (state &b){
return this->h == b.h;
}
};
vector<state> dp[200005];
vector<ii> sum[200005];
///get the sum of values in column x, up to height H
inline lint getsum(int x, lint H){
if(x == -1) return 0;
auto it = upper_bound(all(sum[x]), ii(H, 1023456678901234LL));
if(it == sum[x].begin()) return 0;
it--;
return it->second;
}
long long max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> C){
if(n == 1) return 0;
///setting up sum counts
for(int i = 0;i < m;i++){
sum[X[i]].push_back(ii(Y[i], C[i]));
}
for(int i = 0;i < n;i++){
sort(all(sum[i]));
for(int j = 1;j < sz(sum[i]);j++){
sum[i][j].second += sum[i][j-1].second;
}
}
///set up the important values in the dp table
for(int i = 0;i < m;i++){
if(X[i] != 0) dp[X[i]-1].push_back({Y[i], 0, 0, 0});
if(X[i] != n-1) dp[X[i]+1].push_back({Y[i], 0, 0, 0});
}
for(int i = 0;i < n;i++){
dp[i].push_back({-1,0,0,0}); ///represent not taking anything
sort(all(dp[i]));
dp[i].erase(unique(all(dp[i])), dp[i].end());
}
///now do dp
for(auto &s : dp[0]){
s.P = getsum(1, s.h);
s.I = -getsum(0, s.h);
s.D = getsum(1, s.h) - getsum(0, s.h);
}
for(int i = 1;i < n;i++){
///I to I and I to P
lint bestI = 0;
auto it = dp[i-1].begin();
for(auto &s : dp[i]){
while(it != dp[i-1].end()){
if(it->h >= s.h){
bestI = max(bestI, it->I);
it++;
}
else break;
}
///I to I
s.I = max(s.I, bestI + getsum(i-1, s.h) - getsum(i, s.h));
///I to P
s.P = max(s.P, bestI + getsum(i-1, s.h) + getsum(i+1, s.h));
}
///D to D and P to D
reverse(all(dp[i]));
reverse(all(dp[i-1]));
lint bestPD = 0;
it = dp[i-1].begin();
for(auto &s : dp[i]){
while(it != dp[i-1].end()){
if(it->h <= s.h){
bestPD = max(bestPD, it->P);
bestPD = max(bestPD, it->D);
it++;
}
else break;
}
///D to D and P to D
s.D = max(s.D, bestPD + getsum(i+1, s.h) - getsum(i, s.h));
}
reverse(all(dp[i]));
reverse(all(dp[i-1]));
///D -1 to I -1
dp[i][0].I = max(dp[i][0].I, dp[i-1][0].D);
///P to P 2 spaces away
if(i >= 2){
lint bestP = 0;
for(auto &s : dp[i-2]) bestP = max(bestP, s.P);
for(auto &s : dp[i]){
s.P = max(s.P, bestP + getsum(i+1, s.h));
}
}
}
lint ans = 0;
for(int i = 0;i < n;i++){
/*
show(i);
for(auto s : dp[i]){
cerr << s.h << ": ";
show3(s.P, s.I, s.D);
}
cerr << endl << endl;
//*/
for(auto &s : dp[i]){
ans = max(ans, s.P);
ans = max(ans, s.I);
ans = max(ans, s.D);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
19516 KB |
Output is correct |
2 |
Correct |
71 ms |
21368 KB |
Output is correct |
3 |
Correct |
15 ms |
14388 KB |
Output is correct |
4 |
Correct |
14 ms |
14392 KB |
Output is correct |
5 |
Correct |
259 ms |
47164 KB |
Output is correct |
6 |
Correct |
288 ms |
55960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
163 ms |
27872 KB |
Output is correct |
3 |
Correct |
181 ms |
31652 KB |
Output is correct |
4 |
Correct |
61 ms |
19620 KB |
Output is correct |
5 |
Correct |
75 ms |
21556 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 |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
14 ms |
14292 KB |
Output is correct |
11 |
Correct |
14 ms |
14292 KB |
Output is correct |
12 |
Correct |
75 ms |
22172 KB |
Output is correct |
13 |
Correct |
90 ms |
24536 KB |
Output is correct |
14 |
Correct |
73 ms |
21040 KB |
Output is correct |
15 |
Correct |
88 ms |
22132 KB |
Output is correct |
16 |
Correct |
71 ms |
20936 KB |
Output is correct |
17 |
Correct |
76 ms |
22148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14292 KB |
Output is correct |
2 |
Correct |
13 ms |
14292 KB |
Output is correct |
3 |
Correct |
62 ms |
22348 KB |
Output is correct |
4 |
Correct |
42 ms |
19852 KB |
Output is correct |
5 |
Correct |
103 ms |
30832 KB |
Output is correct |
6 |
Correct |
98 ms |
30780 KB |
Output is correct |
7 |
Correct |
97 ms |
30756 KB |
Output is correct |
8 |
Correct |
97 ms |
30752 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 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
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 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
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 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14292 KB |
Output is correct |
2 |
Correct |
13 ms |
14292 KB |
Output is correct |
3 |
Correct |
62 ms |
22348 KB |
Output is correct |
4 |
Correct |
42 ms |
19852 KB |
Output is correct |
5 |
Correct |
103 ms |
30832 KB |
Output is correct |
6 |
Correct |
98 ms |
30780 KB |
Output is correct |
7 |
Correct |
97 ms |
30756 KB |
Output is correct |
8 |
Correct |
97 ms |
30752 KB |
Output is correct |
9 |
Correct |
125 ms |
30840 KB |
Output is correct |
10 |
Correct |
82 ms |
29308 KB |
Output is correct |
11 |
Correct |
185 ms |
48880 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
5 ms |
9684 KB |
Output is correct |
14 |
Correct |
6 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9640 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
19516 KB |
Output is correct |
2 |
Correct |
71 ms |
21368 KB |
Output is correct |
3 |
Correct |
15 ms |
14388 KB |
Output is correct |
4 |
Correct |
14 ms |
14392 KB |
Output is correct |
5 |
Correct |
259 ms |
47164 KB |
Output is correct |
6 |
Correct |
288 ms |
55960 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
163 ms |
27872 KB |
Output is correct |
9 |
Correct |
181 ms |
31652 KB |
Output is correct |
10 |
Correct |
61 ms |
19620 KB |
Output is correct |
11 |
Correct |
75 ms |
21556 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
5 ms |
9684 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
14 ms |
14292 KB |
Output is correct |
17 |
Correct |
14 ms |
14292 KB |
Output is correct |
18 |
Correct |
75 ms |
22172 KB |
Output is correct |
19 |
Correct |
90 ms |
24536 KB |
Output is correct |
20 |
Correct |
73 ms |
21040 KB |
Output is correct |
21 |
Correct |
88 ms |
22132 KB |
Output is correct |
22 |
Correct |
71 ms |
20936 KB |
Output is correct |
23 |
Correct |
76 ms |
22148 KB |
Output is correct |
24 |
Correct |
14 ms |
14292 KB |
Output is correct |
25 |
Correct |
13 ms |
14292 KB |
Output is correct |
26 |
Correct |
62 ms |
22348 KB |
Output is correct |
27 |
Correct |
42 ms |
19852 KB |
Output is correct |
28 |
Correct |
103 ms |
30832 KB |
Output is correct |
29 |
Correct |
98 ms |
30780 KB |
Output is correct |
30 |
Correct |
97 ms |
30756 KB |
Output is correct |
31 |
Correct |
97 ms |
30752 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 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
40 |
Halted |
0 ms |
0 KB |
- |