fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.Arrays;
  4. import java.util.function.Function;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. System.out.println(Arrays.toString(
  12. t.apply(new int[] {1,2,2,2,5,7,10,20})
  13. .apply(new int[] {1,1,2,3,6,6,15,21,21,22})
  14. ));
  15. }
  16.  
  17. static int[] toyStore(int[]g,int[]b) {
  18. int gl=g.length,bl=b.length,gp=0,bp=0,ap=0;
  19. int[] a=new int[gl],s=new int[bl];
  20. for (;bp<bl;) {
  21. while(gp<gl&&g[gp]<=b[bp])a[ap++]=g[gp++];
  22. s[bp++]=ap>0?a[--ap]:0;
  23. }
  24. return s;
  25. }
  26. static int[]t(int[]g,int[]b){int l=g.length,L=b.length,G=0,B=0,A=0;int[]a=new int[l],s=new int[L];for(;B<L;){while(G<l&&g[G]<=b[B])a[A++]=g[G++];s[B++]=A>0?a[--A]:0;}return s;}
  27.  
  28. static Function<int[],Function<int[],int[]>>t=
  29. g->b->{int l=g.length,L=b.length,G=0,B=0,A=0;int[]a=new int[l],s=new int[L];for(;B<L;){while(G<l&&g[G]<=b[B])a[A++]=g[G++];s[B++]=A>0?a[--A]:0;}return s;};
  30. }
Success #stdin #stdout 0.2s 320640KB
stdin
Standard input is empty
stdout
[1, 0, 2, 2, 5, 2, 10, 20, 7, 0]