#include "fish.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
typedef long long int ll;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W) {
ll ans =0;
ll a[300005];
ll flag=0,flag1=0;
for(int i =0;i<M;i++)
{
if(X[i]%2==1)
{
flag=1;
}
if(Y[i]!=0)
{
flag1=1;
}
a[X[i]]+=W[i];
}
if(flag==0)
{
ans=0;
for(int i =0;i<M;i++)
{
ans+=W[i];
}
}
else if(flag1==0)
{
ans=0;
ll dp[300005][2];
memset(dp,0,sizeof(dp));
dp[1][0]=a[1];
dp[1][1]=a[0];
for(int i =2;i<N;i++)
{
dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][0]);
dp[i][1]=max({dp[i-2][0]+a[i-1],dp[i-1][1],dp[i-2][1]+a[i-1]});
}
ans=max(dp[N-1][0],dp[N-1][1]);
}
else
{
ll b[300005][2];
memset(b,0,sizeof(b));
for(int i =0;i<M;i++)
{
b[Y[i]][X[i]]+=W[i];
}
for(int i =1;i<N;i++)
{
b[i][0]+=b[i-1][0];
b[i][1]+=b[i-1][1];
}
ans=max(b[N-1][0],b[N-1][1]);
if(N>2)
{
for(int i =0;i<N;i++)
{
ll cnt=b[N-1][1]-b[i][1];
ans=max(ans,cnt+b[i][0]);
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
9180 KB |
Output is correct |
2 |
Correct |
29 ms |
9672 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
89 ms |
14308 KB |
Output is correct |
6 |
Correct |
89 ms |
14308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7336 KB |
Output is correct |
2 |
Correct |
67 ms |
11160 KB |
Output is correct |
3 |
Correct |
63 ms |
11984 KB |
Output is correct |
4 |
Correct |
26 ms |
9164 KB |
Output is correct |
5 |
Correct |
32 ms |
9668 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
4 ms |
7252 KB |
Output is correct |
10 |
Correct |
4 ms |
7252 KB |
Output is correct |
11 |
Correct |
4 ms |
7252 KB |
Output is correct |
12 |
Correct |
27 ms |
9172 KB |
Output is correct |
13 |
Correct |
32 ms |
9660 KB |
Output is correct |
14 |
Correct |
28 ms |
9200 KB |
Output is correct |
15 |
Correct |
31 ms |
9432 KB |
Output is correct |
16 |
Correct |
28 ms |
9172 KB |
Output is correct |
17 |
Correct |
31 ms |
9428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
8 ms |
7252 KB |
Output is correct |
3 |
Correct |
19 ms |
8624 KB |
Output is correct |
4 |
Correct |
15 ms |
8168 KB |
Output is correct |
5 |
Correct |
32 ms |
9664 KB |
Output is correct |
6 |
Correct |
28 ms |
9676 KB |
Output is correct |
7 |
Correct |
34 ms |
9664 KB |
Output is correct |
8 |
Correct |
50 ms |
9660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
7228 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
7228 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
7228 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
8 ms |
7252 KB |
Output is correct |
3 |
Correct |
19 ms |
8624 KB |
Output is correct |
4 |
Correct |
15 ms |
8168 KB |
Output is correct |
5 |
Correct |
32 ms |
9664 KB |
Output is correct |
6 |
Correct |
28 ms |
9676 KB |
Output is correct |
7 |
Correct |
34 ms |
9664 KB |
Output is correct |
8 |
Correct |
50 ms |
9660 KB |
Output is correct |
9 |
Incorrect |
31 ms |
9556 KB |
1st lines differ - on the 1st token, expected: '99999', found: '33334' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
9180 KB |
Output is correct |
2 |
Correct |
29 ms |
9672 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
89 ms |
14308 KB |
Output is correct |
6 |
Correct |
89 ms |
14308 KB |
Output is correct |
7 |
Correct |
4 ms |
7336 KB |
Output is correct |
8 |
Correct |
67 ms |
11160 KB |
Output is correct |
9 |
Correct |
63 ms |
11984 KB |
Output is correct |
10 |
Correct |
26 ms |
9164 KB |
Output is correct |
11 |
Correct |
32 ms |
9668 KB |
Output is correct |
12 |
Correct |
4 ms |
7252 KB |
Output is correct |
13 |
Correct |
4 ms |
7252 KB |
Output is correct |
14 |
Correct |
4 ms |
7252 KB |
Output is correct |
15 |
Correct |
4 ms |
7252 KB |
Output is correct |
16 |
Correct |
4 ms |
7252 KB |
Output is correct |
17 |
Correct |
4 ms |
7252 KB |
Output is correct |
18 |
Correct |
27 ms |
9172 KB |
Output is correct |
19 |
Correct |
32 ms |
9660 KB |
Output is correct |
20 |
Correct |
28 ms |
9200 KB |
Output is correct |
21 |
Correct |
31 ms |
9432 KB |
Output is correct |
22 |
Correct |
28 ms |
9172 KB |
Output is correct |
23 |
Correct |
31 ms |
9428 KB |
Output is correct |
24 |
Correct |
4 ms |
7252 KB |
Output is correct |
25 |
Correct |
8 ms |
7252 KB |
Output is correct |
26 |
Correct |
19 ms |
8624 KB |
Output is correct |
27 |
Correct |
15 ms |
8168 KB |
Output is correct |
28 |
Correct |
32 ms |
9664 KB |
Output is correct |
29 |
Correct |
28 ms |
9676 KB |
Output is correct |
30 |
Correct |
34 ms |
9664 KB |
Output is correct |
31 |
Correct |
50 ms |
9660 KB |
Output is correct |
32 |
Incorrect |
5 ms |
7228 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
33 |
Halted |
0 ms |
0 KB |
- |