#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=3e5+9;
const ll INF=1e9;
ll used[N];
ll dp[N][3];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
ll ans=0,cnt=0,cntt=0,cnt2=0,sum1=0,sum2=0;
for(auto to:W){
ans+=to;
}
for(auto to:X){
if(to&1) cnt++;
if(to<=1) cntt++;
}
for(auto to:Y){
if(to==0) cnt2++;
}
if(cnt==0) return ans;
else if(cnt2==M){
for(ll i=0; i<=N; i++){
used[i]=0;
dp[i][0]=dp[i][1]=0;
}
for(ll i=0;i<M;i++){
used[X[i]+1]=W[i];
}
// dp[-1][0]=dp[-1][1]=0;
/// 0 - used, 1 - free
for(ll i=1;i<=N;i++){
if(i==1){
dp[i][0]=used[i+1],dp[i][1]=0;
continue;
}
else{
dp[i][0]=max({dp[i-1][0]-used[i],dp[i-2][1]+used[i-1],dp[i-2][0]})+used[i+1];
dp[i][1]=max(dp[i-1][1],dp[i-1][0]);
}
}
return max(dp[N][1],dp[N][0]);
}
else if(cntt==M){
for(ll i=0; i<M; i++){
if(X[i]==0) sum1+=W[i];
else sum2+=W[i];
}
return max(sum1,sum2);
}
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
51 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2132 KB |
Output is correct |
2 |
Correct |
28 ms |
2632 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
110 ms |
7280 KB |
Output is correct |
6 |
Correct |
91 ms |
7276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
17 ms |
4412 KB |
Output is correct |
4 |
Correct |
12 ms |
4308 KB |
Output is correct |
5 |
Correct |
37 ms |
5704 KB |
Output is correct |
6 |
Correct |
39 ms |
5732 KB |
Output is correct |
7 |
Correct |
27 ms |
5716 KB |
Output is correct |
8 |
Correct |
29 ms |
5720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
17 ms |
4412 KB |
Output is correct |
4 |
Correct |
12 ms |
4308 KB |
Output is correct |
5 |
Correct |
37 ms |
5704 KB |
Output is correct |
6 |
Correct |
39 ms |
5732 KB |
Output is correct |
7 |
Correct |
27 ms |
5716 KB |
Output is correct |
8 |
Correct |
29 ms |
5720 KB |
Output is correct |
9 |
Incorrect |
27 ms |
2652 KB |
1st lines differ - on the 1st token, expected: '99999', found: '99998' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2132 KB |
Output is correct |
2 |
Correct |
28 ms |
2632 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
110 ms |
7280 KB |
Output is correct |
6 |
Correct |
91 ms |
7276 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |