Problem 2 Codeforces Round #632 (Div. 2)

Revision en1, by Rishi_Kant, 2020-07-31 22:51:36

Please help me in B. Here is my solution 88615363. My approach

  1. I create two variables c and d to count number of 1 and -1 in list a from index[0,n-1]. I didn't take the last index as it can't be i, it only can be j as i < j.

  2. I check if a[0] is equal to b[0]. if not just print NO.

  3. Now go in else block. I used a loop from last index to 1. Now check if a[i] == b[i] then just check if a[i-1] is 1 then remove count of c by 1 and if a[i-1] is -1 then remove count of d by 1.

  4. Else if a[i] < b[i] then check count of c. If it is greater then 0 remove count by 1 else break and if a[i] > b[i] Just check then check count of d. Please tell me where I did wrong. Thanku

Tags #greedy, #632 div 2

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Rishi_Kant 2020-07-31 22:51:36 745 Initial revision (published)