小明种苹果(续)

 

问题描述:


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m, current, temp, sum = 0, cutTreeNum = 0, t3Num = 0;
        boolean[] vis = new boolean[n + 5];
        for (int i = 0; i < n; i++) {
            m = scanner.nextInt();
            current = scanner.nextInt();
            for (int j = 1; j < m; j++) {
                temp = scanner.nextInt();
                if (temp <= 0) {
                    current += temp;
                } else if (current > temp) {
                    current = temp;
                    vis[i] = true;
                }
            }
            sum += current;
        }
        for (int i = 0; i < n; i++) {
            if (vis[i])
                cutTreeNum++;
            if (vis[(i - 2 + n) % n] && vis[(i - 1 + n) % n] && vis[i])
                t3Num++;
        }
        System.out.println(sum + " " + cutTreeNum + " " + t3Num);
    }
}

 

 

 

 

 

posted @ 2019-11-16 23:47  miss-pw  阅读(164)  评论(0编辑  收藏  举报