Advertisement
Guest User

Solution 1

a guest
Nov 11th, 2019
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  // Check Examples
  4.  
  5.  // Compiler version JDK 11.0.2
  6.  
  7.  class Dcoder
  8.  {
  9.     private static ArrayList<Integer> groups = new ArrayList<Integer>();
  10.    
  11.     public static void main(String args[])
  12.     {
  13.         Scanner input = new Scanner(System.in);
  14.         int principal = input.nextInt();
  15.         while(--principal > 0)
  16.             addToGroup(shiftGroups(principal));
  17.        
  18.         if(groups.isEmpty()) groups.add(0);
  19.         System.out.println(groups.size());
  20.     }
  21.    
  22.     public static boolean shiftGroups(int amount) {
  23.         if(groups.isEmpty()) return true;
  24.        
  25.         if(groups.size() == 100000-1) return false;
  26.         if(groups.get(groups.size() - 1) < 3) return false;
  27.         return true;
  28.     }
  29.    
  30.     public static void addToGroup(boolean isShifting) {
  31.         if(isShifting)
  32.             groups.add(0);
  33.        
  34.         int index = groups.size() - 1;
  35.         int newInt = groups.get(index) + 1;
  36.         groups.set(index, groups.get(index) + 1);
  37.     }
  38.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement