3

Please help what is wrong with my approach? Codeforces Round #693 (Div. 3) Probl...

 1 year ago
source link: http://codeforces.com/blog/entry/108311
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

2 pointer with greedy

I tried to solve the problem using 2 pointer with greedy. It was failing at 1146th test case

My approach was to check if adding the element x to current score will increase it compared to opponents score than add it otherwise just not let the opponent to take their score.

My logic was similar to one of the logics that I found in submissions. The new approach was that I didn.t included the current score of the player and compared only the values if it is greater than that of opponents then add it to the score. This solution worked out. But according to me even if I compare using the current score the answer should be more accurate, which is not the case, what can be wrong please help.

WRONG SUBMISSIONhttps://codeforces.com/contest/1472/submission/177486281

CORRECT SUBMISSIONhttps://codeforces.com/contest/1472/submission/177486439

CODE TO BE COMPARED IN main()

WRONG

 while(i<ev || j<od){
            if(f){
                if(i<ev &&(j==od || a+e[i]>=b+o[j])){
                    a+=e[i];i++;
                }else{                    
                    j++;
                }
                f=0;
            }else{
                if(j<od && (i==ev || b+o[j]>=a+e[i])){
                    b+=o[j];j++;
                }else{                    
                    i++;
                }
                f=1;
            }            
        }

CORRECT

 while(i<ev || j<od){
            if(f){
                if(i<ev &&(j==od || e[i]>=o[j])){
                    a+=e[i];i++;
                }else{                    
                    j++;
                }
                f=0;
            }else{
                if(j<od && (i==ev || o[j]>=e[i])){
                    b+=o[j];j++;
                }else{                    
                    i++;
                }
                f=1;
            }            
        }

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK