#include<bits/stdc++.h>
//#include "prison.h"
#pragma GCC optimize ("O3")
using namespace std;
#define el "\n"
#define se " "
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
const ll INF=1e18,ch=1e18;
ll a,b,c,d,n,COST,t,last,ab,ba,n1,n2,fl1,fl2,o1,o2,flag,flag1,flag2,g,m,m1,m2,i,j,lr,f,k,l,r,y,o,p,mx=-ch,mx1=-ch,mx2=-ch,q,q1,q2,q3,q4,mn=ch,mn1=ch,mn2=ch,f1,f2,f3,pos,ans,sum,sz=1,MOD=1e9+7,zero=0,a1,b1,c1,val,sum1,cur,res,ans1,res1,kk,kkk,cnt,cnt1,fl;
pair < ll , pair < ll , ll > > A[300005];
ll B[4][300005];
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W)
{
n=N;k=M;
for(i=1;i<=k;i++)
{
A[i].ff=X[i-1]+1;
A[i].ss.ff=Y[i-1]+1;
if (A[i].ss.ff==1) flag++;
A[i].ss.ss=W[i-1];
if (A[i].ff%2!=0) q1++;
if (A[i].ff<=2) q2++;
}
if (q1==k)
{
for(i=1;i<=k;i++)
{
f+=A[i].ss.ss;
}
return f;
}
else if (q2==k)
{
for(i=1;i<=k;i++)
{
B[A[i].ff][A[i].ss.ff]=A[i].ss.ss;
}
for(i=1;i<=300001;i++)
{
f+=max(B[1][i],B[2][i]);
}
return f;
}
else if (flag==k)
{
ll dp[300005][3]={0};
ll C[300005]={0};
for(i=1;i<=k;i++)
{
C[A[i].ff]=A[i].ss.ss;
}
dp[1][0]=0;
dp[1][1]=C[2];
for(i=2;i<=n;i++)
{
dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
dp[i][1]=max({dp[i-1][1]-C[i],dp[i-2][1],dp[i-2][0]+C[i-1]})+C[i+1];
}
return max(dp[n][0],dp[n][1]);
}
else
{
ll dp[3005][3005][3]={0};
ll C[3005][3005]={0};
for(i=1;i<=k;i++)
{
C[A[i].ss.ff][A[i].ff]=A[i].ss.ss;
}
for(q=1;q<=n;q++)
{
dp[q][1][0]=0;
dp[q][1][1]=C[q][2];
for(i=2;i<=n;i++)
{
dp[q][i][0]=max(dp[q][i-1][0],dp[q][i-1][1]);
dp[q][i][1]=max({dp[q][i-1][1]-C[q][i],dp[q][i-2][1],dp[q][i-2][0]+C[q][i-1]})+C[q][i+1];
}
f+=max(dp[q][n][0],dp[q][n][1]);
}
return f;
}
}
//int main()
//{
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// cin>>n>>a>>b;
// vector < vector < int > > v=devise_strategy(a,b);
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
286804 KB |
Output is correct |
2 |
Correct |
133 ms |
287732 KB |
Output is correct |
3 |
Correct |
106 ms |
282944 KB |
Output is correct |
4 |
Correct |
107 ms |
282956 KB |
Output is correct |
5 |
Correct |
193 ms |
297108 KB |
Output is correct |
6 |
Correct |
193 ms |
297076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
282984 KB |
Output is correct |
2 |
Incorrect |
154 ms |
291996 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '56666856824716' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
282928 KB |
Output is correct |
2 |
Correct |
104 ms |
282984 KB |
Output is correct |
3 |
Correct |
123 ms |
285496 KB |
Output is correct |
4 |
Correct |
113 ms |
284820 KB |
Output is correct |
5 |
Correct |
129 ms |
287692 KB |
Output is correct |
6 |
Correct |
124 ms |
287672 KB |
Output is correct |
7 |
Correct |
130 ms |
287620 KB |
Output is correct |
8 |
Correct |
139 ms |
287696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
283040 KB |
Output is correct |
2 |
Correct |
133 ms |
283028 KB |
Output is correct |
3 |
Incorrect |
107 ms |
282956 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
283040 KB |
Output is correct |
2 |
Correct |
133 ms |
283028 KB |
Output is correct |
3 |
Incorrect |
107 ms |
282956 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
283040 KB |
Output is correct |
2 |
Correct |
133 ms |
283028 KB |
Output is correct |
3 |
Incorrect |
107 ms |
282956 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
282928 KB |
Output is correct |
2 |
Correct |
104 ms |
282984 KB |
Output is correct |
3 |
Correct |
123 ms |
285496 KB |
Output is correct |
4 |
Correct |
113 ms |
284820 KB |
Output is correct |
5 |
Correct |
129 ms |
287692 KB |
Output is correct |
6 |
Correct |
124 ms |
287672 KB |
Output is correct |
7 |
Correct |
130 ms |
287620 KB |
Output is correct |
8 |
Correct |
139 ms |
287696 KB |
Output is correct |
9 |
Runtime error |
396 ms |
583232 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
286804 KB |
Output is correct |
2 |
Correct |
133 ms |
287732 KB |
Output is correct |
3 |
Correct |
106 ms |
282944 KB |
Output is correct |
4 |
Correct |
107 ms |
282956 KB |
Output is correct |
5 |
Correct |
193 ms |
297108 KB |
Output is correct |
6 |
Correct |
193 ms |
297076 KB |
Output is correct |
7 |
Correct |
103 ms |
282984 KB |
Output is correct |
8 |
Incorrect |
154 ms |
291996 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '56666856824716' |
9 |
Halted |
0 ms |
0 KB |
- |