Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String args[]){
- ArrayList<Integer> al = solve();
- if (al.size() == 0 || al.get(0) == -1) System.out.println("-1");
- else {
- System.out.println(al.size());
- for (int i = 0; i < al.size(); i++){
- System.out.print(al.get(i) + " ");
- }
- }
- }
- public static ArrayList<Integer> solve(){
- ArrayList<Integer> sol = new ArrayList<Integer>();
- ArrayList<Integer> al = new ArrayList<Integer>();
- Scanner in = new Scanner(System.in);
- int n = in.nextInt(), sum = 0, cut = 0;
- for (int i = 1; i <= n; i++){
- int num = in.nextInt();
- sum += num;
- if (al.contains(num)){
- sol = new ArrayList<Integer>();
- sol.add(-1);
- return sol;
- }
- if (num > 0) al.add(num);
- if (sum == 0){
- al = new ArrayList<Integer>();
- sol.add(i - cut);
- cut = i;
- }
- }
- if (sum != 0){
- sol = new ArrayList<Integer>();
- sol.add(-1);
- }
- return sol;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement