Last active
June 1, 2017 08:17
-
-
Save dolpen/232d1c31c8042749b538e339238a95f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.PrintWriter; | |
import java.util.Arrays; | |
public class Main { | |
static byte[] b = new byte[40000]; | |
static int c, i, j, k, l, m, n, w, x, y = 0; | |
public static void main(String[] a) throws Exception { | |
l = System.in.read(b); | |
int[] s = new int[m = r()], p = new int[n = r()], d; | |
for (c = i = j = k = 0; j < m; c = Math.max(c, s[j++] = r())) ; | |
for (d = new int[c + 1]; k < n; p[k++] = r()) ; | |
Arrays.fill(d, w = 0xfffff); | |
for (Arrays.sort(p); i < n; ++i) | |
for (j = 0; j <= i; d[x] = x) { | |
if ((x = p[i] * p[j++]) >= c) { | |
if (d[c] > x) d[c] = x; | |
break; | |
} | |
} | |
for (i = k = c; --i >= 0; d[i] = d[k]) if (d[i] < w) k = i; | |
PrintWriter o = new PrintWriter(System.out); | |
for (; ++i < m; o.println(d[s[i]] - s[i])) ; | |
o.close(); | |
} | |
static int r() { | |
w = 0; | |
while ((x = b[y++]) > 0 && x < 48) ; | |
do { | |
w = w * 10 + (x - 48); | |
} while ((x = b[y++]) > 0 && x >= 48); | |
return w; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*;import java.util.*;public class Main{static byte[] b=new byte[40000];static int c,i,j,k,l,m,n,w,x,y=0;public static void main(String[] a)throws Exception{l=System.in.read(b);int[] s=new int[m=r()],p=new int[n=r()],d;for(c=i=j=k=0;j<m;c=Math.max(c,s[j++]=r()));for(d=new int[c+1];k<n;p[k++]=r());Arrays.fill(d,w=0xfffff);for(Arrays.sort(p);i<n;++i)for(j=0;j<=i;d[x]=x){if((x=p[i]*p[j++])>=c){if(d[c]>x)d[c]=x;break;}}for(i=k=c;--i>=0;d[i]=d[k])if(d[i]<w)k=i;PrintWriter o=new PrintWriter(System.out);for(;++i<m;o.println(d[s[i]]-s[i]));o.close();}static int r(){w=0;while((x=b[y++])>0&&x<48);do{w=w*10+(x-48);}while((x=b[y++])>0&&x>=48);return w;}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package poh; | |
import java.io.PrintWriter; | |
import java.util.Arrays; | |
public class Main { | |
static byte[] b = new byte[40000]; | |
static int c, i, j, k, l, m, n, q, w, x, y, z = 0xfffff; | |
public static void main(String[] a) throws Exception { | |
l = System.in.read(b); | |
c = i = j = k = y = 0; | |
int[] s = new int[m = r()], p = new int[n = r()], d; | |
for (; j < m; c = Math.max(c, s[j++] = r())) ; | |
for (; k < n; p[k++] = r()) ; | |
d = new int[c + 1]; | |
Arrays.sort(p); | |
Arrays.fill(d, z); | |
for (; i < n; ++i) | |
for (j = 0; j <= i; d[q] = q) { | |
if ((q = p[i] * p[j++]) >= c) { | |
d[c] = d[c] > q ? q : d[c]; | |
break; | |
} | |
} | |
for (i = k = c; --i >= 0; d[i] = d[k]) if (d[i] < z) k = i; | |
PrintWriter o = new PrintWriter(System.out); | |
for (; ++i < m; o.println(d[s[i]] - s[i])) ; | |
o.close(); | |
} | |
static int r() { | |
w = 0; | |
while ((x = b[y++]) > 0 && x < 48) ; | |
do { | |
w = w * 10 + (x - 48); | |
} while ((x = b[y++]) > 0 && x >= 48); | |
return w; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
minimize processor : work -> min