//#include "fish.h"
#include<bits/stdc++.h>
#define ll long long
#include <vector>
ll mx(ll a,ll b){
if(a>b) return a;
return b;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
ll dp[N][2],a[N];
ll sum=0,say=0;
for(int i=0;i<N;i++){
dp[i][0]=dp[i][1]=a[i]=0;
}
for(int i=0;i<M;i++){
a[X[i]]=1ll*W[i];
if(X[i]%2==1){
say=1;
}
sum+=W[i];
}
dp[0][1]=a[0];
dp[1][0]=a[0];
dp[1][1]=a[1];
ll ans=mx(a[0],a[1]);
for(int i=2;i<N;i++){
if(i>2){
dp[i][0]=mx(dp[i-3][0]+a[i-1]+a[i-2],mx(dp[i-1][1],dp[i-1][0]));
}
else{
dp[i][0]=dp[i-1][1];
}
dp[i][1]=dp[i-1][0]+a[i];
}
ans=mx(dp[N-1][1],dp[N-1][0]);
if(say==0){
ans=sum;
}
return ans;
}
/*
9 9
0 0 1
1 0 4
2 0 5
3 0 2
4 0 1
5 0 5
6 0 3
7 0 2
8 0 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
4196 KB |
Output is correct |
2 |
Correct |
28 ms |
4932 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2516 KB |
Output is correct |
5 |
Correct |
94 ms |
9624 KB |
Output is correct |
6 |
Correct |
94 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
16 ms |
3612 KB |
Output is correct |
4 |
Correct |
14 ms |
3412 KB |
Output is correct |
5 |
Correct |
28 ms |
4932 KB |
Output is correct |
6 |
Correct |
24 ms |
4948 KB |
Output is correct |
7 |
Correct |
30 ms |
4940 KB |
Output is correct |
8 |
Correct |
26 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
16 ms |
3612 KB |
Output is correct |
4 |
Correct |
14 ms |
3412 KB |
Output is correct |
5 |
Correct |
28 ms |
4932 KB |
Output is correct |
6 |
Correct |
24 ms |
4948 KB |
Output is correct |
7 |
Correct |
30 ms |
4940 KB |
Output is correct |
8 |
Correct |
26 ms |
4948 KB |
Output is correct |
9 |
Incorrect |
28 ms |
4928 KB |
1st lines differ - on the 1st token, expected: '99999', found: '66666' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
4196 KB |
Output is correct |
2 |
Correct |
28 ms |
4932 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2516 KB |
Output is correct |
5 |
Correct |
94 ms |
9624 KB |
Output is correct |
6 |
Correct |
94 ms |
9676 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |