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 Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int n =5;
  14. int required[] = new int[n+1];
  15. int stock[] = new int[n+1];
  16. int cost[] = new int[n+1];
  17. int budget = 0;
  18.  
  19. int i =1;
  20. int sum;
  21. int low=0;
  22. long high = (long)1e18;
  23.  
  24. while(low<high){
  25.  
  26. int mid = (int)(low+high)/2;
  27. sum = 0;
  28. for(int j =1;j<n;j++){
  29. int p = required[j]*mid;
  30. int d = p-stock[j];
  31. if(d<0){
  32. d = 0 ;
  33. }
  34. sum = sum + d*cost[j] ;
  35. }
  36.  
  37. if(sum<=budget){
  38. budget = mid;low=mid+1;
  39. }else{
  40. high = mid-1;
  41. }
  42. i++;
  43. }
  44. System.out.println(budget);
  45. }
  46. }
Success #stdin #stdout 0.07s 52560KB
stdin
Standard input is empty
stdout
-743309312