Last active
October 16, 2016 12:09
-
-
Save yssharma/f6953300aef28d8dcbea4823300f2930 to your computer and use it in GitHub Desktop.
Codeforces 376 Div 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package codeforces.x376; | |
import java.util.Scanner; | |
/** | |
* Created by ysharma on 10/16/16. | |
*/ | |
public class B { | |
public static void main(String[] args) { | |
new B().doit(); | |
} | |
private void doit(){ | |
Scanner sc = new Scanner(System.in); | |
int N = sc.nextInt(); | |
int[] a = new int[N]; | |
for(int i=0; i<N; i++){ | |
a[i] = sc.nextInt(); | |
} | |
for(int i=0; i<N; i++){ | |
a[i] = a[i] % 2; // buy all 2 pizzas | |
if(a[i] == 1){ | |
if(i == N-1){ | |
System.out.println("NO"); | |
return; | |
} else { | |
a[i] = 0; | |
a[i+1] = a[i+1] - 1; | |
} | |
} | |
} | |
for(int i : a){ | |
if(a[i] != 0){ // change this to : if(i != 0){ | |
System.out.println("NO"); | |
return; | |
} | |
} | |
System.out.println("YES"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment