-
CodeForces #1285B Just Eat It [java]알고리즘 구현 2020. 3. 23. 23:18
import java.util.Scanner; public class JustEatIt_1285B { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); long[] a; long pre = 0, po = 0; int n; for (int i = 0; i < t; i++) { n = scan.nextInt(); a = new long[n]; boolean yes = true; pre = 0; po = 0; for (int j = 0; j < n; j++) { a[j] = scan.nextLong(); pre = pre + a[j]; if (pre <= 0) { yes = false; } } for (int j = n - 1; j > 0; j--) { po = po + a[j]; if (po <= 0) { yes = false; } } if (yes == true) System.out.println("YES"); else System.out.println("NO"); } scan.close(); } }
prefix 사용
'알고리즘 구현' 카테고리의 다른 글
CodeForces #734B Anton And Digits [java] (0) 2020.04.03 CodeForces #466C Number Of Ways [java] (0) 2020.03.23 CodeForces #1003C Intense Heat [java] (0) 2020.03.23 CodeForces #118A String Task [java] (0) 2020.03.18 CodeForces #71A Way Too Long Words [java] (0) 2020.03.18