#include <vector>
using namespace std;
long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W)
{
bool subt1=1,subt2=1,subt3=1;
for (int i=0;i<M;i++)
{
if (X[i]%2)
subt1=0;
if (X[i]>1)
subt2=0;
if (Y[i]!=0)
subt3=0;
}
if (subt1)
{
long long sm=0;
for (int i=0;i<M;i++)
sm+=W[i];
return sm;
}
if (subt2)
{
long long sm[2];
for (int i=0;i<M;i++)
{
sm[X[i]]+=W[i];
}
return max(sm[0],sm[1]);
}
if (subt3)
{
long long dp[N][2]={};
int val[N]={};
for (int i=0;i<M;i++)
val[X[i]]=W[i];
dp[0][0]=0,dp[0][1]=val[0];
long long ans=0;
for (int i=1;i<N;i++)
{
if (i>1)
dp[i][0]=max(dp[i-2][0],dp[i-2][1])+val[i];
if (i<N-1)
dp[i][1]=max(dp[i][0],dp[i-1][0]+val[i]);
ans=max(ans,max(dp[i][0],dp[i][1]));
}
return ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3672 KB |
Output is correct |
2 |
Correct |
18 ms |
4408 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
54 ms |
13768 KB |
Output is correct |
6 |
Correct |
56 ms |
13904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '140731548994945' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
2140 KB |
Output is correct |
3 |
Incorrect |
10 ms |
4392 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '21049836049923' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
2140 KB |
Output is correct |
3 |
Incorrect |
10 ms |
4392 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '21049836049923' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3672 KB |
Output is correct |
2 |
Correct |
18 ms |
4408 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
54 ms |
13768 KB |
Output is correct |
6 |
Correct |
56 ms |
13904 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '140731548994945' |
8 |
Halted |
0 ms |
0 KB |
- |