fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Main
  9. {
  10. public static boolean isPossible(int[] t, int[] d, int w, int m){
  11. int n = t.length;
  12. long lit = 0;
  13. for(int i=0;i<n;i++){
  14. if(m == 9){
  15. System.out.println((m/d[i])*t[i]);
  16. }
  17. lit += (((m-1)/d[i])+1)*t[i];
  18. }
  19.  
  20. // System.out.println(m + " " + lit);
  21. return lit>=w;
  22. }
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. // your code goes here
  26. Scanner sc = new Scanner(System.in);
  27. int w = sc.nextInt();
  28. int n = sc.nextInt();
  29. int[] t = new int[n];
  30. int[] d = new int[n];
  31.  
  32. for(int i=0;i<n;i++){
  33. t[i] = sc.nextInt();
  34. }
  35. for(int i=0;i<n;i++){
  36. d[i] = sc.nextInt();
  37. }
  38.  
  39.  
  40. int l = 0;
  41. int r = (int)1e9;
  42. int ans = 0;
  43. while(l <= r){
  44. int m = l+ (r-l)/2;
  45. if(isPossible(t,d,w,m)){
  46. ans = m;
  47. r = m - 1;
  48. }
  49. else{
  50. l = m + 1;
  51. }
  52. }
  53. System.out.println(ans);
  54. }
  55. }
Success #stdin #stdout 0.14s 56624KB
stdin
24
6
3
3
2
1
2
3
9
10
2
8
6
9
stdout
3
0
8
1
2
3
11