#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e18;
struct fish{
int y=0;
ll cost,f0=0,f1=0;
friend bool operator<(fish a,fish b){
return a.y<b.y;
}
};
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<vector<fish>> dp(N+1);
vector<int> check(N+1,0);
for(int i=0;i<M;i++){
X[i]++;Y[i]++;
dp[X[i]].push_back({Y[i]-1,W[i],0,0});
check[X[i]]|=(Y[i]==1);
}
for(int i=0;i<=N;i++){
if(!check[i]) dp[i].push_back({0,0,0,0});
dp[i].push_back({N,0,0,0});
sort(dp[i].begin(),dp[i].end());
}
dp[0].front().f0=dp[0].front().f1=0;
dp[0].back().f0=dp[0].back().f1=-inf;
for(int i=1;i<=N;i++){
int cur=0;
ll sum=0,csum=0,Max=dp[i-1][0].f0;
//cout << i << '\n';
for(auto &a:dp[i]){
csum+=a.cost;
while(cur+1<(int)dp[i-1].size() && dp[i-1][cur+1].y<a.y){
sum+=dp[i-1][cur].cost;cur++;
Max=max(Max,dp[i-1][cur].f0-sum);
}
a.f0=Max+sum+dp[i-1][cur].cost;
}
Max=dp[i-1].back().f1+csum;cur++;
for(int j=(int)dp[i].size()-1;j>=0;j--){
auto &a=dp[i][j];
while(cur && dp[i-1][cur-1].y>a.y){
cur--,Max=max(Max,dp[i-1][cur].f1+csum);
}
csum-=a.cost;
a.f1=Max-csum;
//cout << '*' << Max << ' ' << cur << '\n';
}
/*
for(auto a:dp[i]){
cout << a.f0 << ' ' << a.f1 << '\n';
}
*/
dp[i].front().f0=max(dp[i].front().f0,dp[i-1].front().f1);
dp[i].back().f1=max({dp[i].back().f1,dp[i].back().f0,dp[i-1].front().f1});
}
return max(dp[N].front().f1,dp[N].back().f0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
15540 KB |
Output is correct |
2 |
Correct |
55 ms |
18072 KB |
Output is correct |
3 |
Correct |
14 ms |
10796 KB |
Output is correct |
4 |
Correct |
16 ms |
10964 KB |
Output is correct |
5 |
Correct |
141 ms |
33572 KB |
Output is correct |
6 |
Correct |
172 ms |
39200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
80 ms |
21416 KB |
Output is correct |
3 |
Correct |
97 ms |
25248 KB |
Output is correct |
4 |
Correct |
47 ms |
15544 KB |
Output is correct |
5 |
Correct |
53 ms |
18080 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
14 ms |
10808 KB |
Output is correct |
11 |
Correct |
14 ms |
10784 KB |
Output is correct |
12 |
Correct |
47 ms |
15612 KB |
Output is correct |
13 |
Correct |
53 ms |
17976 KB |
Output is correct |
14 |
Correct |
44 ms |
15620 KB |
Output is correct |
15 |
Correct |
50 ms |
17344 KB |
Output is correct |
16 |
Correct |
49 ms |
15680 KB |
Output is correct |
17 |
Correct |
52 ms |
17348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
10844 KB |
Output is correct |
2 |
Correct |
15 ms |
10792 KB |
Output is correct |
3 |
Incorrect |
36 ms |
12568 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '26722970331638' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Incorrect |
1 ms |
352 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '217145724910' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Incorrect |
1 ms |
352 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '217145724910' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Incorrect |
1 ms |
352 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '217145724910' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
10844 KB |
Output is correct |
2 |
Correct |
15 ms |
10792 KB |
Output is correct |
3 |
Incorrect |
36 ms |
12568 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '26722970331638' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
15540 KB |
Output is correct |
2 |
Correct |
55 ms |
18072 KB |
Output is correct |
3 |
Correct |
14 ms |
10796 KB |
Output is correct |
4 |
Correct |
16 ms |
10964 KB |
Output is correct |
5 |
Correct |
141 ms |
33572 KB |
Output is correct |
6 |
Correct |
172 ms |
39200 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
80 ms |
21416 KB |
Output is correct |
9 |
Correct |
97 ms |
25248 KB |
Output is correct |
10 |
Correct |
47 ms |
15544 KB |
Output is correct |
11 |
Correct |
53 ms |
18080 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
14 ms |
10808 KB |
Output is correct |
17 |
Correct |
14 ms |
10784 KB |
Output is correct |
18 |
Correct |
47 ms |
15612 KB |
Output is correct |
19 |
Correct |
53 ms |
17976 KB |
Output is correct |
20 |
Correct |
44 ms |
15620 KB |
Output is correct |
21 |
Correct |
50 ms |
17344 KB |
Output is correct |
22 |
Correct |
49 ms |
15680 KB |
Output is correct |
23 |
Correct |
52 ms |
17348 KB |
Output is correct |
24 |
Correct |
13 ms |
10844 KB |
Output is correct |
25 |
Correct |
15 ms |
10792 KB |
Output is correct |
26 |
Incorrect |
36 ms |
12568 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '26722970331638' |
27 |
Halted |
0 ms |
0 KB |
- |