cccミンさんはリンゴを作ります


T 201909-2:http://118.190.20.162/view.page?gpid=T93
テストサンプル
5
4 10 0 9 0 
4 10 -2 7 0
2 10 0
4 10 -3 5 0
4 10 -1 8 0

4
4 74 -7 -12 -5
5 73 -8 -6 59 -4
5 76 -5 -10 60 -2
5 80 -6 -15 59 0
考え方
73 -8 -6 59 -4,       73,       ,  ,73-8-6=59
    59,    59,             ,  es == 1      
         sum
     False         
コード
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();  // n   
		int [][] apples = new int[n+1][1000 + 7];
		long [] sum = new long[n];  //           
		long sum1 = 0; //           
		long d = 0; //       
		int [] es = new int[n+2];  //        
		
		for (int i = 0; i < n; i++) {
			int m = in.nextInt();
			boolean f = true; //           
			for (int j = 0; j < m; j++) {
				apples[i][j] = in.nextInt();
				
				if(apples[i][j] <= 0) {
					sum[i] += apples[i][j];
				}else {
					if(j > 0 && sum[i] > apples[i][j] && f) {
						d++;
						es[i+1] = 1;
						f = false;   //              
					}
					//         
					sum[i] = apples[i][j];   
				}
			}
		}
		
		for (int i = 0; i < n; i++) {
			sum1 += sum[i];   //         
		}

		/**
		 *        3     
		 */
		long sum2 = 0;
		for(int i = 1; i <= n; i++)
	    {
	        if(es[i] == 1)
	        {
	            if(i==1 && es[n]  == 1&& es[i+1] == 1)
	                sum2++;
	            else if(i==n && es[i-1] == 1 && es[1] == 1)
	                sum2++;
	            else if(es[i-1] == 1 && es[i+1] == 1)
	                sum2++;
	        }
	    }
		
		System.out.print(sum1 + " " + d + " " + sum2);
	}
}