MJSaif's blog

By MJSaif, history, 4 months ago, In English

987C - Three displays

in this problem, in an array S we need to find three indices (i<j<k) such that 1<=(i,j,k)<=n && Si < Sj < Sk... there is another array C.. && the sum of (Ci,Cj,Ck) should be minimum...

my implementation is below..

define N 1000000007

vector a(3000),c(3000);

vector<vector> dp(3001,vector (4,-1));

ll f(int i,int p,int mx){

if(p==0)    return 0;

 if(i==0){
    if(p==1 && a[0]<mx)     return c[0];
    return N;
 }

 if(dp[i][p]!=-1)    return dp[i][p];

 ll pick=N;
 if(a[i]<mx){
    pick=0ll+c[i]+f(i-1,p-1,a[i]);
 }
 ll no_pick=f(i-1,p,mx);
 return dp[i][p]=min(no_pick,pick);

}

int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int n;      cin>>n;
for(int i=0;i<n;i++)    cin>>a[i];
for(int i=0;i<n;i++)    cin>>c[i];
int ans=f(n-1,3,N);
cout<<(ans==N?-1:ans)<<nl;

return 0;

}

for the test case ,

5

2 4 5 4 10

40 30 20 10 40

the answer is: 90 but my output is: 70

why is my code is not giving the right output.. where should I make a change??

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By MJSaif, history, 5 months ago, In English

I have been doing Codeforces (CF) for 6 months. Most of the time, I solve A and B problems of Div2 contests within 1 hour. I want to increase my speed and improve my ability to solve more problems during Div2 contests. For that, I want to practice only on CF. Actually, the problems on AtCoder and SPOJ seem harder and boring to me.

So, can practicing only on CF help me improve my problem-solving ability?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it