You are viewing a single comment's thread. Return to all comments →
hello rýanfehr18 sir i have found more optimize solution complexity is O(1) here is the code
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class FairRotation { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int B[] = new int[N];int sum=0,sum1=0; for(int B_i=0; B_i < N; B_i++){ B[B_i] = B[B_i]+in.nextInt(); if(B[B_i]%2==1&&B_i+1<N) {sum+=2; B[B_i+1]+=1; } if(B_i==N-1&&B[B_i]%2==1) { System.out.println("NO");break; } if(B_i==N-1&&B[B_i]%2==0) { System.out.println(sum);break; } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Fair Rations
You are viewing a single comment's thread. Return to all comments →
hello rýanfehr18 sir i have found more optimize solution complexity is O(1) here is the code