Problem Link : http://www.codechef.com/problems/MARCHA2
Solution :
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
*
* @author XCoder
*/
class JohnyAndTheBeanstalk {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter pw = new PrintWriter(System.out);
public static int readIntLine() throws IOException {
return Integer.parseInt(br.readLine());
}
public static long readLongLine() throws IOException {
return Long.parseLong(br.readLine());
}
public static void main(String[] args) throws IOException {
int test = readIntLine();
while (test-- > 0) {
int levels = readIntLine();
String str = br.readLine();
String split[] = str.split(" ");
int k[] = new int[split.length];
for (int i = 0; i < split.length; i++) {
k[i] = Integer.parseInt(split[i]);
}
int stem = 1;
boolean valid = true;
for (int i = 0; i < k.length; i++) {
stem -= k[i];
stem *= 2;
if (stem < 0) {
valid = false;
break;
}
// System.out.println("in loop "+stem);
}
// System.out.println(stem);
if (stem > 0 ){
valid = false;
}
if (valid) {
pw.println("Yes");
} else {
pw.println("No");
}
}
pw.flush();
pw.close();
}
}
No comments:
Post a Comment